Skip to content

Forward

See Also: Broadcast, Delegate, Get, Send, Set

Purpose

To invoke the superclass implementation of a procedure or function.

Syntax

Forward {Get | Set | Send} {message} ...

What It Does

A function or a procedure of a class sometimes needs to execute the code defined for the same message in an object's superclass. When this is true, we say that the implementation of the message in the class is an augmentation. The Forward command is used to invoke the code defined for a message in a superclass of the object's class.

An object that declares functions and procedures actually creates a class, especially for the object. When the Forward command is used in the functions and procedures within an object declaration, the system will forward to an implementation of the object's class, before forwarding to an implementation of the object's superclass.

Example

The following example shows the augmentation of six messages. Three messages are implemented in the object's class and three messages are implemented in the superclass of the object. All the implementations in the class forward to the superclass. The implementations in the object forward to either the class or superclass, depending on whether there is an implementation in the object's class.

Class cSuperClass Is A Button
    Procedure Construct_Object
        Forward Send
        // Always forward construct_object!
    Property String psProperty Public "Some Property"
    End_Procedure

    Procedure OnEvent1 String sString1 String sString2
        Showln "In OnEvent1 of the Superclass."
        Showln "String 1 = " sString1 ", String 2 = " sString2
    End_Procedure

    Procedure OnEvent2 String sString1 String sString2
        Showln "In OnEvent2 of the Superclass."
        Showln "String 1 = " sString1 ", String 2 = " sString2
    End_Procedure

    Function Func1 String sString1 String sString2 Returns Integer
        Showln "Inside Func1 of cSuperClass"
        Showln "String 1 = " sString1 ", String 2 = " sString2
        Function_Return 1
    End_Function

    Function Func2 String sString1 String sString2 Returns Integer
        Showln "Inside Func2 of cSuperClass"
        Showln "String 1 = " sString1 ", String 2 = " sString2
        Function_Return 2
    End_Function
End_Class

Class cSubClass Is A cSuperClass
    Procedure Set psProperty String sSomeValue
        Showln "In cClass. Setting property to " sSomeValue
        Forward Set
        psProperty to sSomeValue
        Showln "In cClass. All done setting property to " sSomeValue
    End_Procedure

    Procedure OnEvent1 String sParam1 String sParam2
        Showln "In OnEvent1 of cClass - Before Forwarding"
        Forward Send
        OnEvent1 sParam1 sParam2
        Showln "In OnEvent1 of cClass - After Forwarding"
    End_Procedure

    Function Func1 String sParam1 String sParam2 Returns Integer
        Integer iRetVal
        Showln "Inside Func1 of cClass - Before Forwarding"
        Forward Get
        Func1 sParam1 sParam2 To iRetVal
        Showln "Inside Func1 of cClass - After Forwarding"
        Function_Return iRetVal
    End_Function
End_Class

Object oTest Is A cSubClass
    Procedure OnEvent1 String sParam1 String sParam2
        Showln "In OnEvent1 of the object - Before Forwarding"
        Forward Send
        OnEvent1 sParam1 sParam2
        Showln "In OnEvent1 of the object - After Forwarding"
    End_Procedure

    Function Func1 String sParam1 String sParam2 Returns Integer
        Integer iRetVal
        Showln "Inside Func1 of object - Before Forwarding"
        Forward Get
        Func1 sParam1 sParam2 To iRetVal
        Showln "Inside Func1 of object - After Forwarding"
        Function_Return 1
    End_Function

    Procedure OnEvent2 String sParam1 String sParam2
        Showln "In OnEvent2 of the object - Before Forwarding"
        Forward Send
        OnEvent2 sParam1 sParam2
        Showln "In OnEvent2 of the object - After Forwarding"
    End_Procedure

    Function Func2 String sParam1 String sParam2 Returns Integer
        Integer iRetVal
        Showln "Inside Func2 of object - Before Forwarding"
        Forward Get
        Func2 sParam1 sParam2 To iRetVal
        Showln "Inside Func2 of object - After Forwarding"
        Function_Return 1
    End_Function
End_Object