Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Instantiating and managing class-based objects : Publishing and subscribing to class events

Publishing and subscribing to class events

As described previously (see Events of a class), class events allow you to dynamically register one or more event handlers that execute in response to run-time conditions. Thus, you publish the event to notify other parts of the application when a given condition is detected, and one or more event handlers execute in response to this notification. Depending on run-time conditions, you can change the number of event handlers that execute for any given event. In this way, different parts of the application can respond to the same event at different times whenever the event is published. For example, one common use of this mechanism is to help populate one or more data viewers from record buffers whose contents have been updated from a selection in a data browser.
The procedure for using a class event to provide such notifications follows a common pattern.
To set up and use a class event:
1. Define the event in a class definition using the DEFINE EVENT statement (see Defining events within a class).
2. Subscribe one or more handlers to the event using the Subscribe( ) event method (see Specifying handler subscriptions for class events).
3. Publish the event from within the class that defines it for a given condition using the Publish( ) event method, which runs all event handlers that are subscribed to the event, and processes any values returned from the Publish( ) method parameters (see Publishing class events).
Note: This section describes event subscription and publishing mechanisms that apply in common to both instance events and static events, but to instance events in particular. For information on the unique features of working with static events, see Accessing static members.
* Specifying handler subscriptions for class events
* Publishing class events