A delegate instance is created using the operator of delegate instance creation. A created delegate instance refers to:
A static method specified in a delegate declaration expression.
An object instance and its method specified in a delegate declaration expression.
Another delegate.
Once created, a delegate instance always refers to the same object or method. When two delegate instances are combined or a delegate instance is deleted from another instance, a new instance is created with its own invocation list; the invocation lists of the operands remain unchanged.
Delegate UserEventHandler(x, y, z: integer);
Class UserObject
//Redetermine abstract event
Public Event OnUserEvent1: UserEventHandler;
Constructor UserObject();
Begin
//Set event handlers
//The following procedures are executed when the event occurs
//ForEven1 and ForEven2
OnUserEvent1 := ForEven1;
OnUserEvent1 += ForEven2;
End Constructor;
//Event handling procedures
Sub ForEven1(x, y, z: integer);
Begin
End Sub;
Sub ForEven2(x, y, z: integer);
Begin
End Sub;
//Procedure of creating and invoking delegate instance
Sub RunDelegate(x, y, z: integer);
Var
d: UserEventHandler;
Begin
//Create a delegate instance
d := New UserEventHandler(ForEven1);
//Delegate invocation. The ForEven1 procedure is executed on invocation
d(x, y, z);
End Sub;
End Class;
See also: