Previous Topic Next topic Print topic


Delegates and Events - in COBOL and Java

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.
    

method-id main static.
*> Combining delegates
    set MsgArrivedEvent to MsgArrivedEvent + method My_MsgArrivedEventCallback
       
    invoke run MsgArrivedEvent("Test message")
    set MsgArrivedEvent to MsgArrivedEvent - method My_MsgArrivedEventCallback

*> Attaching to an event
    attach method My_MsgArrivedEventCallback to 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.

Delegates and Events in Java

//There is no delegate concept in Java
//The right-side C# program may be mimicked 
//with reflection technology.

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.

Previous Topic Next topic Print topic