Events

Event is a class member that enables an object or class to provide notifications. Application developers can attach executable code to events by supplying event handlers.

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. To specify event handler, use the event assignment statement:

Example

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

Abstract Class BaseClass
    //Abstract event that must be overriden
    Abstract Public Event OnLoad: LoadEventHandler;
End Class;

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

    Public Constructor UserObject();
    Begin
        //Set 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