Events

An event is a class member that enables an object or class to provide notifications. Clients can attach executable code for events by supplying event handlers.

event-declaration:

attributesopt   event-modifiersopt   Event   identifier   :   type;

event-modifiers:

event-modifier

event-modifiers   event-modifier

event-modifier:

New

Public

Protected

Friend

Private

Shared

Virtual

Final

Override

Abstract

Event declarations are subject to the same rules as method declarations with regard to valid combinations of modifiers.

The type specified in the event declaration, must be a delegate with the same or higher access level as the event access level. An event assignment statement is used to indicate the event handler.

Example

Delegate LoadEventHandler(x, y, z: integer);
Delegate ErrorEventHandler(x, y: integer);

Abstract Class BaseClass
    //Abstract event to be redeclared
    Abstract Public Event OnLoad: LoadEventHandler;
End Class;

Class UserObject: BaseClass
    //Redeclaring abstract event
    Public Override Event OnLoad: LoadEventHandler;
    //Declaring own event
    Public Event OnError: ErrorEventHandler;

    Constructor UserObject();
    Begin
        //Setting event handlers
        OnLoad := Load;
        OnLoad += LoadEx;
        OnError := CheckError;
    End Constructor;
    
    Sub DelEventHandler();
    Begin
        OnLoad := Null;
        OnError := Null;
    End Sub;

    //Event  handling procedures
    Sub Load(x, y, z: integer);
    Begin
        
    End Sub;

    Sub LoadEx(x, y, z: integer);
    Begin
        
    End Sub;

    Sub CheckError(x, y: integer);
    Begin
        
    End Sub;
End Class;

See also:

Classes