Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Howto deregister an event handler

Former Member
0 Kudos

Hi all!

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.

Thx!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can use the ACTIVATION addition to deregister handler methods or register them dynamically..

Addition

... ACTIVATION f

Effect

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.

Note

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.

Example

CLASS C1 DEFINITION.

PUBLIC SECTION.

EVENTS E.

...

ENDCLASS.

CLASS C2 DEFINITION.

PUBLIC SECTION.

METHODS M2 FOR EVENT E OF C1.

ENDCLASS.

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.

METHOD M2.

...

ENDMETHOD.

ENDCLASS.

In this example, the method H->M2 is deregistered and then set dynamically.

Note for all variants:

Note

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.

Regards,

Tanveer.

Please mark helpful answers.

Message was edited by: Tanveer Shaikh

2 REPLIES 2

Former Member
0 Kudos

Hi,

You can use the ACTIVATION addition to deregister handler methods or register them dynamically..

Addition

... ACTIVATION f

Effect

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.

Note

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.

Example

CLASS C1 DEFINITION.

PUBLIC SECTION.

EVENTS E.

...

ENDCLASS.

CLASS C2 DEFINITION.

PUBLIC SECTION.

METHODS M2 FOR EVENT E OF C1.

ENDCLASS.

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.

METHOD M2.

...

ENDMETHOD.

ENDCLASS.

In this example, the method H->M2 is deregistered and then set dynamically.

Note for all variants:

Note

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.

Regards,

Tanveer.

Please mark helpful answers.

Message was edited by: Tanveer Shaikh

Former Member
0 Kudos

HI

GOOD

ADD_EVENT_HANDLER

Method to register an event handler for an event.

REMOVE_EVENT_HANDLER

Method to deregister an event handler from an event.

THANKS

MRUTYUN