Mentor SAP
Register handler object or handler class to events at runtime. The syntax for this is SET HANDLER.

Event Handler Registration

The definition of the handler method only specifies how and to which event of which class the method will react. At runtime, it needs to be determined which possible reactions will actually take place and when each of these reactions will happen.

 

When triggering instance events, you also have to specify which event the reaction will trigger. If instance methods are set to carry out the reaction, you also have to specify which instances will perform the reaction.

 

These specifications are collectively known as registration. Registration is always carried out using the trigger. When the event is triggered, the runtime uses the registrations of the trigger to determine which event handler methods need to be called.

 

In this example, handler methods are defined for the event of the vehicle class, the car rental class, and the vehicle registration class. However, you can only predetermine which car rental instances and vehicle registration instances will react to which vehicle instance, and when they will do so.

 

Registrations can also be revoked.

 

 

Registering Event Handling – Syntax

Events are registered using the SET HANDLER statement. Registration is only active at program runtime.

 

With instance events, FOR is followed by the reference to the object that triggers the event.

 

 

The addition ACTIVATION 'X' is optional during registration. To undo the registration, use ACTIVATION ' '.

 

You can register several methods with one SET HANDLER statement:

 

SET HANDLER ref_handler_1->on_eventname_1 ...

 

ref_handler_n->on_eventname_n FOR ...

 

With the addition of ALL INSTANCES an event handler can be registered for all instances of the class that defines the instance event. This is the only way to register handlers for instances that have not yet been created.

 

Event Handler Deregistration

Every object or class that defines events has an internal table known as the handler table. All handler methods that are registered to the various events are listed within the handler table. For instance methods, the handler table also contains references to the registered objects. ​

 

Hint: Objects that are registered for event handling are not deleted by the garbage collector, even if there are no remaining references to them.

 

Note: It is possible to add or remove event handlers for a given event while an event handler for this exact event is executed. If a new event handler is registered, then this event handler is added to the end of the sequence and executed when its time comes. If an existing event handler is deregistered, then this handler is deleted immediately from the event handler method sequence.

 

 

Visibility Sections in Event Handling

Events are subject to the visibility concept and can, therefore, be considered public, protected, or private. Event handler methods also have visibility attributes.

 

Visibility Sections of Events

 

Visibility Sections of Handler Methods