Try OpenEdge Now
skip to main content
ABL Reference
Class Events Reference : Using class events
 

Using class events

For any ABL class event, used by itself or to implement an interface or inherited abstract event, you must follow these general steps:
1. Define the event using the DEFINE EVENT statement.
2. Subscribe one or more handlers to the event using the Subscribe( ) event method. You can subscribe handlers to an event anywhere the event is accessible in an application.
3. Publish the event for a given condition using the Publish( ) event method, which runs all subscribed event handlers for the event. You can publish the event only from within the class definition that implements a non-abstract definition for the event.
4. Process any values returned from the Publish( ) method parameters.
At any point after subscribing event handlers, you can optionally unsubscribe any event handlers you no longer need using the Unsubscribe( ) event method. Thus, like named events for procedures, class events allow you to dynamically define and undefine alternate routines that execute in response to the event.
Note that similar to ABL class events, only the class that implements a non-abstract definition for a .NET event can publish it. This includes any ABL class that derives from and implements a .NET abstract class defining abstract events or that implements a .NET interface defining event prototypes.
However by convention, a .NET class that defines an event also typically defines a corresponding protected OnEventName( ) method that allows a derived class to publish the event, where EventName specifies the name of the .NET event and the signature defines a System.EventArgs (or derivation) as input. If the OnEventName( ) method is overrideable (virtual in C#), you can also override this method in an ABL derived class. If you do override this method, you must also invoke the super class implementation of OnEventName( ) from within the overriding method (using the SUPER system reference) in order to ensure that all subscribed .NET delegates also respond to the event. For more information on overriding .NET methods, see the METHOD statement reference entry.
To allow .NET events from .NET form and control objects to be published as part of the OpenEdge GUI for .NET, you must block to display the .NET forms and allow your subscribed event handlers to execute in response to any published events. To enable this .NET event handling, ABL provides WAIT-FOR statement syntax that blocks for both GUI for .NET events and ABL handle-based object events. For more information, see the WAIT-FOR statement (.NET andABL) reference entry.
Otherwise, you can work with .NET events in exactly the same way as ABL class events.