Skip to content

Delegation_Mode - cObject

Determines if and how unknown messages are delegated

Type: Property
Access: Read/Write
Data Type: Integer
Parameters: None

Syntax

Property Integer Delegation_Mode
Access Type Syntax
Read Access: Get Delegation_Mode to IntegerVariable
Write Access: Set Delegation_Mode to IntegerVariable/Value

Description

The delegation_mode of an object determines the method by which unknown messages are handled. When a message is not understood by an object (i.e., the message is not defined in the object or within the object's class structure) , the delegation_mode determines how this is handled. The following modes are supported:

Constant Meaning
Delegate_to_Parent Delegate_to_Parent causes the message to be sent to the parent of the object. This is the default mode for all classes, except for Array and its subclasses.
No_Delegation The no_delegation mode results in an error.
No_Delegate_or_Error The no_delegate_or_error mode causes the message to be ignored.The object will, in effect, ignore all messages that it does not understand. This is the default mode of the Array class and its subclasses.
Return_Invalid_Message The return_invalid_message mode returns the integer value of the unknown message_id. This is rarely used.
Delegate_Prior_Level The delegate_prior_level mode causes unknown messages to be sent up the focus tree. This is rarely used.

The most common delegation mode settings are delegate_to_parent and no_delegation.

// disable delegation...we want to see our errors right away!
set Delegation_Mode to No_Delegation
integer eDelegate
// restore normal delegation, if needed
get Delegation_Mode to eDelegate
If (eDelegate <> Delegate_To_Parent)  Begin
     set Delegation_Mode to delegate_to_parent
End

You will normally not want disable delegation and disable errors. When invalid methods are sent to an object with this mode set, you will receive no notification that the message was not understood. Usually this is not desired and it is quite difficult to debug. The Array class does this for historical reasons.

set Delegation_Mode to No_Delegate_Or_Error // you will rarely use this

You can use the Delegation_Mode property of an object to ignore errors when you are unsure whether the object will understand the message. For example, the StatusBar object id is stored in a property called Statusbar_Id. When you send a message to the object stored in this property, you might send a message that is not understood by this object. If you want to get your message executed only when available and otherwise have it be ignored, you can use code like this:

Procedure DoMyAction
    Handle hoStatusbar
    Integer eDelegation

    Get StatusBar_Id To hoStatusBar
    If (hoStatusBar > 0) Begin
        Get Delegation_Mode Of hoStatusBar To eDelegation
        Set Delegation_Mode Of hoStatusBar To No_Delegate_Or_Error
        Send ShowProductName Of hoStatusBar "DataFlex is the best!"
        Set Delegation_Mode Of hoStatusBar To eDelegation
    End
End_Procedure

DataFlex uses a similar technique in messages from toolbars. See for example at DoSendToDeoFocus.