DELEGATE-ENDDELEGATE
|
WNSupported in Synergy .NET on Windows
|
|
|
[access] DELEGATE name[<T[(constraints)], ...>], delegate_type parameter_def . . . ENDDELEGATE
Arguments
access
(optional) One of the following access modifiers:
Access is not restricted. This is the most accessible option. (default)
Access is limited to the current assembly.
Access is limited to the containing type or types derived from the containing type. (nested delegates only)
Access is limited to the containing type. This is the least accessible option. (nested delegates only)
name
The name of the delegate to declare.
T
A generic type parameter, which indicates the delegate is a generic type and which acts as a placeholder for which an actual type will be substituted when the member is used. Note that you can use any unused letter (not just T). See Generic types (.NET) for more information.
constraints
One or more of the following constraints:
- A base class, to stipulate that the generic type parameter must inherit from that specific base class. If no base class is specified, the default is System.Object.
- One or more interfaces, to stipulate that the generic type parameter must implement the specified interfaces.
- A constructor, to allow creating an instance of the type parameter using the NEW syntax.
Multiple constraints must be separated by commas. See Constraints for more information.
delegate_type
Any data type that can be used as a return value for .NET. See the Where Data Types Can Be Used table.
parameter_def
The definition of a parameter that is unique within this method. Each parameter definition has the syntax that’s described in Defining a parameter.
Discussion
A delegate enables you to pass a method as a parameter value. A delegate can be used as a type wherever a type can be used within the class (for example, local variable and field types).
The example below defines a delegate class member named mydelegate that defines a method prototype, and the mymethod method uses mydelegate as a parameter value. Mymethod is called, passing in the subthis method as the parameter value for p1. Within mymethod, subthis is called with a parameter value of 5. Subthis returns 5*2, which equals 10.
class class1 public delegate mydelegate, i4 p1, i4 enddelegate public method mymethod, i4 p1, @mydelegate record v1, i4 proc v1 = p1(5) ;call the delegate passing in a 5 mreturn v1 endmethod public method subthis, i4 p1, i4 proc mreturn p1 * 2 endmethod endclass c1, @class1 md, @class1.mydelegate v1, i4 c1 = new class1() md = new class1.mydelegate(c1.subthis) v1 = c1.mymethod(md)