MathDelegateCreateDelegate Method

Creates a delegate object that calls a specified Wolfram Language function.

Remarks

This method is comparable to the CreateDelegate(Type, Object, String) method, except that it creates delegates whose action is to call a Wolfram Language function.

Use this method to easily create Wolfram Language event handler functions from a .NET language. It provides similar functionality to the AddEventHandler Wolfram Language function.

C#
// C# example:
myTextBox.KeyPress += (KeyPressEventHandler) MathDelegate.CreateDelegate(typeof(KeyPressEventHandler), "KeyPressHandlerFunction", ml); 

' VB example:
AddHandler myTextBox.KeyPress, CType(MathDelegate.CreateDelegate(GetType(KeyPressEventHandler), "KeyPressHandlerFunction", ml), KeyPressEventHandler)

The Wolfram Language function can be the name of a function as a string, or a pure function like "(x = #)&". The function will be passed all the arguments that the corresponding delegate type takes, and it should return a result of the same type as the delegate type. If the delegate type returns void, the result from the Wolfram Language function is ignored.

The call is automatically wrapped in NETBlock unless you use the one overload that allows you to specify otherwise.

Overload List

CreateDelegate(Type, String) The link that is used is the one given by StdLink.Link.
CreateDelegate(Type, String, IKernelLink) Uses the specified link.
CreateDelegate(Type, String, IKernelLink, Boolean, Boolean) Use this overload in cases where you need to specify advanced behavior.

See Also