Publish and subscribe to class events
- Last Updated: May 29, 2019
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
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:
- Define the event in a class definition using the
DEFINE EVENTstatement (see Define events within a class). - Subscribe one or more handlers to the event using the
Subscribe( )event method (see Specify handler subscriptions for class events). - 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 thePublish( )method parameters (see Publish class events).