Previous Topic Next topic Print topic


Delegates and Events - in COBOL and

Delegates and Events in Managed COBOL

delegate-id MsgArrivedEventHandler.
procedure division using by value msg as string. 
end delegate.

class-id a.
01 MsgArrivedEvent type MsgArrivedEventHandler event static.
    *> Delegates must be used with events in COBOL

method-id main static.
*> Combining delegates
    set MsgArrivedEvent to MsgArrivedEvent + method self::My_MsgArrivedEventCallback
       *> Throws exception if obj is null
    invoke run MsgArrivedEvent("Test message")
    set MsgArrivedEvent to MsgArrivedEvent - method self::My_MsgArrivedEventCallback

*> Attaching to an event
    attach method self::My_MsgArrivedEventCallback to self::MsgArrivedEvent
    invoke run MsgArrivedEvent("Test message 2")
end method.

method-id My_MsgArrivedEventCallback static.
procedure division using by value str as string.
    display str
end method.
end class.
Previous Topic Next topic Print topic