.NET/Link API Version 1.5 USE FRAMES

MathDelegate.CreateDelegate Method

Creates a delegate object that calls a specified Mathematica function.

Overload List

The link that is used is the one given by StdLink.Link.

public static Delegate CreateDelegate(Type,string);

Uses the specified link.

public static Delegate CreateDelegate(Type,string,IKernelLink);

Use this overload in cases where you need to specify advanced behavior.

public static Delegate CreateDelegate(Type,string,IKernelLink,bool,bool);

Remarks

This method is comparable to the CreateDelegate method, except that it creates delegates whose action is to call a Mathematica function.

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

 // 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 Mathematica 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 Mathematica function is ignored.

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

See Also

MathDelegate Class | Wolfram.NETLink Namespace