Events

Events allow an object or class to trigger event handler methods in another class or object. Just as, in a normal method call, a method can be called by any number of users, any number of event handler methods can be called when an event is triggered. The trigger and handler are coupled at runtime. In a normal method call, the caller specifies which method it wants to call; the relevant method must be available. With events, the handler specifies the events to which it wants to react; a handler method must be registered for each event.

The events in a class can be triggered in methods of the same class using the

RAISE EVENT statement. An event handler method can be declared for an event evtof the class class using a method declaration (from another class) or using the FOR EVENT evt OF class addition (in the same class). The parameter interfaces for events are similar to those for methods, except that they only have output parameters, not input parameters. These parameters can be passed from the trigger to the event handler methods (using the RAISE EVENT statement), which then accept them as input parameters.

Triggers and handlers are assigned automatically at runtime, using the SET HANDLER statement. Triggers and handlers can be objects or classes, according to whether an instance or static event (or handler method) is being used. If an event is triggered, the asssociated event handler methods are executed in all registered handlers.

At present, all registered event handler methods are run synchronously - that is, each is executed completely, after the RAISE EVENT statement, before the next statement is processed. This also applies to events that are triggered during event handling.

Instance events

Instance events are declared using the EVENTS statement. They can only be triggered in instance methods.

Static events

Static events are declared using the CLASS-EVENTS statement. All methods (instance or static) can trigger them, but only static events can be triggered by static methods.