Editar

Partilhar via


Session.BindSubscription(Codeunit) Method

Version: Available or changed with runtime version 1.0.

Binds the event subscriber methods in the codeunit to the current codeunit instance for handling the events that they subscribe to. This essentially activates the subscriber functions for the codeunit instance.

Syntax

[Ok := ]  Session.BindSubscription(Codeunit: Codeunit)

Note

This method can be invoked without specifying the data type name.

Parameters

Codeunit
 Type: Codeunit
The codeunit that contains the event subscribers.

Return Value

[Optional] Ok
 Type: Boolean
true if the event subscriber methods bind successfully to the codeunit instance and no errors occurred, otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.

Remarks

You can only call this method on codeunits that have the EventSubscriberInstance Property set to Manual.

The codeunit instance that event subscribers are bound to will be this exact instance. Events will be raised on this instance. You can't bind the same instance more than once, but you can bind multiple instances of the same codeunit. This condition will result in an event subscriber call on each bound instance when a given event is raised.

Example

The following sample code illustrates a typical use of the BindSubscription method.

procedure MyFunction()
var  
    Subscriber: Codeunit Subscriber;  
begin
    // Set global information on the subscriber codeunit if required  
    // You can rely on the instance being the same as the one receiving the event subscriber call  
  
    Subscriber.MySetGlobalInfo(123); //info you can later test in the subscriber event method
    BindSubscription(Subscriber);  
    DoSomething();  // After binding, all subscriptions on Subscriber are "active".  
end; // Notice, that when Subscriber goes out of scope, all bindings are removed.  
  

Session Data Type
Get Started with AL
Developing Extensions