Delegate
See Also: Delegation, Broadcast, Forward, Get, Send, Set
Purpose
To direct a message to the parent of a named object.
Syntax
Delegate {Get | Set | Send} {message}...
What It Does
Delegation is the redirection of a message to the parent of a named object. Normal delegation of a message occurs if an object that receives a message cannot process it. This means that there is no implementation of the message defined in the object declaration or in the object's class.
The Delegate command is used to explicitly delegate a message to an object's parent. Any message may be delegated to a parent. The command is functionally equivalent to using a Get, Set, or Send command of the parent of an object.
Example
// These two lines do the same thing.
Delegate
Send DoSave Param1 Param2
Send DoSave Of (Parent(Self)) Param1 Param2
In the following example, a nested set of objects is defined where a child is a parent of one object that is the child of the other. One message, Procedure Test, is defined at every level of the hierarchy. The child delegates Test to its parent, and the parent delegates Test to the grandparent. Two other messages, Proc_1 and Function_1, are implemented in the parent but not in the child. The Delegate Send and Delegate Get commands of the child object execute the code defined in the parent object.
Object oGrandParentObject Is A Group
Procedure Test
Showln "In Test Function of " (Name(Self))
End_Procedure
Object oParentObject Is A Group
Procedure Test
Showln "In Test Function of " (Name(Self))
Delegate Send Test
End_Procedure
Object oChildObject Is A Button
Procedure Test
Integer iTest
Showln "In Test Function of " (Name(Self))
Delegate
Send Test
Showln "Before Delegation of Proc_1"
Delegate
Send Proc_1
Showln "After Delegation of Proc_1"
Showln "Before Delegation of Function_1"
Delegate
Get Function_1 "Hello" "World" To iTest
Showln "After Delegation of Function_1"
End_Procedure
End_Object
Procedure Proc_1
Showln "In Proc_1 of " (Name(Self))
End_Procedure
Function Function_1 String sParam1 String sParam2 Returns Integer
Showln "In Function_1 of " (Name(Self)) ". Parameters are " sParam1 ", " sParam2
Function_Return 1
End_Function
End_Object
End_Object
Object oTest Is A Button
Procedure OnClick
Send Test Of (oChildObject(oParentObject(oGrandParentObject(Self))))
End_Procedure
End_Object
The arguments to the Delegate command are the same as those to any Get, Set, or Send command for the object. The parameter list is added to the end of the command just like a normal Get, Set, or Send command. See the example of Function_1 in the example above to see how to use the parameter list with Delegate.