Howto deregister an event handler
Is there a way to deregister an event handler?! The documentation says so, but I cannot find the appropriate command.
The thing is, that the event handler can change for a subsequent call of my function module. So I'd like to set the event handler each time the function module is called, though the control itself isn't changed.
You can use the ACTIVATION addition to deregister handler methods or register them dynamically..
... ACTIVATION f
The optional ACTIVATION addition allows you to undo existing registrations or register new handlers dynamically using a variable. The argument f in the addition must be a field with type C and length 1. If f contains the value SPACE, the event handler method is deregistered. If f contains the value X, the event handler is registered. You do not need the ACTIVATION addition for static registrations.
If an instance triggers an event, the registration is implicitly deleted if the triggering instance is deleted by the automatic memory management (garbage collection).
The addition ACTIVATION SPACE only allows you to delete those registrations set using ACTIVATION 'X'. A single registration cannot be deleted by means of a mass deregistration using FOR ALL INSTANCES ACTIVATION SPACE. Vice versa, individual triggering instances cannot be excluded from registration after a mass registration. The internal handler tables for single and mass registrations are completely independent of each other.
CLASS C1 DEFINITION.
CLASS C2 DEFINITION.
METHODS M2 FOR EVENT E OF C1.
DATA: S TYPE REF TO C1,
H TYPE REF TO C2,
ACTIVE(1) TYPE C VALUE 'X'.
CREATE OBJECT: S, H.
SET HANDLER H->M2 FOR S.
SET HANDLER H->M2 FOR S ACTIVATION SPACE.
SET HANDLER H->M2 FOR S ACTIVATION ACTIVE.
CLASS C2 IMPLEMENTATION.
In this example, the method H->M2 is deregistered and then set dynamically.
Note for all variants:
When you register instance methods as event handlers, note that the registration refers to the current instance and not to the reference variable that is used for registration. Even when the reference variable takes another value after SET HANDLER, the registration of the object remains unchanged. This also affects to the lifetime of objects - an object exists for as long as it is registered as an event handler, even if no more reference variables point to it. The object is either explicitly deregistered using the ACTIVATION addition, or implicitly when the triggering instance no longer exists.
Please mark helpful answers.
Message was edited by: Tanveer Shaikh