Modifying or Adding Event Handling

Introduction

Events provide flexible, loosely coupled communication between objects. The SAS/AF event model is implemented through global event registration, which means that different components can listen to and provide handlers for events that are generated by other objects in the current application, objects in any other SAS/AF application that is also running, or the SAS session itself.
Events notify applications when a resource or state changes. Event handlers manage the corresponding response to any changes. Events occur when a user action takes place (such as a mouse click), when an attribute value is changed, or when a user-defined condition occurs.
SAS/AF software supports system events, which can include user interface events (such as mouse clicks) as well as “attributeName Changed” events that occur when an attribute value is updated. For system events, the value of the State metadata item is “S.” For “attributeName Changed” events, the component must have the SendEvent metadata item for the attribute set to “Yes.” See Enabling Attribute Linking for details.
SAS/AF software includes a SAS Session component that provides access to changes made within the SAS environment. For example, SAS sends a system event when a new libref has been assigned or when a new catalog entry has been added. You can create an instance of the SAS Session component and implement handler methods for the events you want to process. For complete information on the SAS Session component, refer to the SAS Session component topic in the SAS/AF online Help.

What Happens during Event Handling

The SAS/AF event model is straightforward: objects “listen” for events that are sent by the system, by other objects, or by the object itself. If the object has an event handler that is defined to perform some action, then that action occurs when the object receives notification of the event.

Adding Events and Event Handlers to Your Components

SAS/AF software also supports user-defined events, which can be registered to specific classes as needed and can be inherited by subclasses. You can use the Class Editor to add user-defined events and event handlers for a class, or you can use the Properties window to add events and event handlers for an instance of a class. For details on how to work with events and event handlers, see “Adding an event,” “Adding an event handler,” and “Working with events and event handlers in the Class Editor” in the SAS/AF online Help.
You can also add events and event handlers programmatically. To do so, your SCL code should use the _addEventHandler method to indicate that an object should be notified when a certain event occurs and to specify which method should be invoked as the event handler. You would also invoke the _sendEvent method on the appropriate object to send the event and to run the event handling method that you specify in the _addEventHandler call.
The methods that support event communication are part of the Object class. In addition to _sendEvent and _addEventHandler, you can use _deleteEventHandler to indicate that an object should no longer be notified of a particular event.
For more information about these methods, refer to the Object class in the SAS/AF online Help.