External_Message Gotcha
<< Back
This is a bit of an advanced topic. Make sure you understand how
External_Message
works. Try to see if you can follow the code below.
Use DfAllEnt
Class cDemoTree is a TreeView
Procedure OnCreateTree
Handle hItem
Get AddTreeItem "Test" 0 0 0 0 to hItem
Get AddTreeItem "Test" 0 0 0 0 to hItem
End_Procedure // OnCreateTree
Procedure OnItemClick
Showln (Name(Self)) " - " (Window_Handle(Self))
Send Windows_Message (WM_USER+123) 0 0
End_Procedure // OnItemClick
End_Class // cDemoTree
Object oMain is a Panel
Set Size to 140 110
Object oTree1 is a cDemoTree
Set Size to 50 100
Procedure OnTree1Click
Send Info_Box "tree 1's item clicked"
End_Procedure // OnTree1Click
Set External_Message (WM_USER+123) to MSG_OnTree1Click
End_Object // oTree1
Object oTree2 is a cDemoTree
Set Location to 50 0
Set Size to 50 100
Procedure OnTree2Click
Send Info_Box "tree 2's item clicked"
End_Procedure // OnTree2Click
Set External_Message (WM_USER+123) to MSG_OnTree2Click
End_Object // oTree2
End_Object // oMain
Start_UI
Whenever a tree item is clicked, OnItemClick is called. We have 2 objects (oTree1, oTree2) are both based on cDemoTree. In theory,
for each tree object, if you click on an item in oTree1, it should trigger line 20; if you click on an item in oTree2, it should trigger
line 29. In reality, if you click on an item in oTree2, you will get an error message of "Invalid message. MSG_ONTREE1CLICK"
External_Message, unfortunately, is tied to a Windows class (not DF class). In this case, "cVdfTreeView". If you are curious, the
Windows class name can be found inside DfTreevw.pkg. Whenever you set an external message in ANY object for that Windows class, all
objects for that DF Class (and all the subclass) will have that External_Message. All DF Classes and their subclasses will ALWAYS
have the same Windows class.
Some more sample if the explanation wasn't clear.
Class cParentTree is a TreeView // Windows class is "cVdfTreeView"
End_Class // cParentTree
Class cChildTree is a cParentTreeView // Windows class is "cVdfTreeView"
End_Class // cChildTree
Class cDifferentTree is a TreeView // Windows class is "cVdfTreeView"
End_Class // cDifferentTree
Object oTree1 is a cChildTree
Set External_Message (WM_USER+123) to MSG_OnSomething // You just set the External_Message to all the objects that have the Window class "cVdfTreeView"!
End_Object // oTree1
Object oTree2 is a cParentTree // this object will HAVE the External_Message attached to it because they share the same Windows class!
End_Object // oTree2
Object oTree3 is a cDifferentTree // this object will HAVE the External_Message attached to it because they share the same Windows class!
End_Object // oTree3