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:
Set event handler in the form event := sub. The use of this assignment form is available only in the basic type, in which the event is declared.
Extend the event handlers list in the form event += sub.
Reduce the event handlers list in the form event -= sub.
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: