ActiveMathLink

--ActiveX Control for MathLink--

This is just a draft, yet to be much edited.

What is ActiveMathLink?

ActiveMathLink is an ActiveX control for MathLink, which can connect to a Mathematica kernel, make the kernel evaluate a string, obtain its result from the kernel, and disconnect the link to the kernel. If a graphic command is invoked, its result can be displayed on the control.

Since it uses ActiveX technology, ActiveMathLink cannot be used in any platforms but in Windows OS.

Properties and Methods

The properties and methods of ActiveMathLink are listed below:

Property List

Property

Description

BGColor

Background color

Connected

If true, the control is connected to the kernel.

DisplayTextColor

Text color on the control if DisplayTextQ is true

DisplayTextQ

If true, the evaluation result is also displayed on the control; if false, it is not.

Height

Height of the control

InitString

Initial string to be evaluated when a Mathematica kernel is loaded and connected
Default string is as follows:
$Display := OpenTemporary[];
$DisplayFunction = (Module[{tmpstream = $Display, tmpfile}, tmpfile = tmpstream[[1]]; Close[tmpstream]; Display[tmpfile, #1, "Metafile"]; LinkWrite[$ParentLink, DisplayEndPacket[tmpfile]]]; #1)&;
SetOptions[ "stdout", PageWidth->65];
Format[LineBreak[_]]:= "";
Format[Continuation[_]]:= " ";SetAttributes[MessagePacket, HoldFirst];$CharacterEncoding ="Unicode";

Left

Left position of the control

MathIn

Input string to be evaluated by the kernel

MathMsg

Message string from the kernel

MathOut

Output string or evaluation result

MLParms

Path to the kernel
Default string is as follows:
-linklaunch -linkname '\Program Files\Wolfram Research\Mathematica\3.0\MathKernel'

Stretch

If true, an image is stretched to the size of the control; if false, it is not.

Top

Top position of the control

Width

Width of the control

Method List

Method

Description

Connect

Connect to the kernel

Disconnect

Disconnect the link

Evaluate

Evaluate an input string in MathIn and get a result in MathOut

Stop

Stop an evaluation process

ActiveMathLink was tested with Mathematica 3.0.1.1 under Windows 98 Japanese version, and has been working all right with Visual Basic 6.0 and Internet Explorer.

How to get ActiveMathLink

ActiveMathLink is FREE! Your comments are always welcome.

Getting ActiveMathLink is quite easy if you know how to decompress LHA files:

  1. Download the compressed file;

  2. Decompress it;

  3. Invoke SETUP.EXE;

  4. Follow the messages on the screen.

Sample: Using ActiveMathLink with Internet Explorer

Here a sample is presented to demonstrate how to use ActiveMathLink with Internet Explorer 4.0. 

First, type the following HTML source code.

Note: For your convenience, this source code is included in the downloadable compressed file above. It is possible that the code does not work with Internet Explorer 3.0.  If so, uncomment the section in black, use buttons instead and change the textarea name from INPUT to, say, INPUTSTR.

@

<HTML>
<HEAD><TITLE>ActiveMathLink</TITLE></HEAD>
<BODY BGCOLOR=#E8E8E8>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR ALIGN="center">
<TD VALIGN="center" BGCOLOR=#4040C0><FONT SIZE=7 COLOR=#FFFF00><I>ActiveMathLink</I></FONT>
</TD>
</TR>
</TABLE>
<TABLE ALIGN=CENTER CELLSPACING=20>
<TR>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="ConnectBtn"><B>&nbsp;Connect&nbsp;</B></A></TD>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="EvaluateBtn"><B>&nbsp;Evaluate&nbsp;</B></A></TD>
<TD BGCOLOR=#FF4000><FONT SIZE=4 COLOR=#FFFFFF><A NAME="DisconnectBtn"><B>&nbsp;Disconnect&nbsp;</B></A></TD>
</TR>
</TABLE>

<!--If button controls are used instead of strings,
<BR><CENTER><INPUT TYPE="button" NAME="ConnectBtn" VALUE="Connect">
<INPUT TYPE="button" NAME="EvaluateBtn" VALUE="Evaluate">
<INPUT TYPE="button" NAME="DisconnectBtn" VALUE="Disconnect">
</CENTER><BR>
-->


<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad() 'When the page is loaded
ActiveML.BGColor=&HF0F0F0 'Set the background color of the ActiveX control
ActiveML.DisplayTextQ=1 'Display the result on the control
End Sub

Sub ConnectBtn_OnClick() 'Connect to the Mathematica kernel
ActiveML.Connect
End Sub

Sub DisconnectBtn_OnClick() 'Disconnect the link to the Mathematica kernel
ActiveML.Disconnect
End Sub

Sub EvaluateBtn_OnClick() 'Evalution
If ActiveML.Connected Then 'If the control is connected to the kernel
ActiveML.MathIn=Input.Value 'Input is the input string. Copy it to MathIn.
ActiveML.Evaluate 'Invoke the evaluation command
Out.Value=ActiveML.MathOut 'Get the result in MathOut and copy it to Out.
Else 'If the control is not yet connected to the kernel
MsgBox "Not connected to Kernel yet.",0,"Connection error"
'Display the error message
End If
End Sub
-->
</SCRIPT>
<CENTER>

<FONT SIZE=5 COLOR=#995599>Input:</FONT><BR>
<TEXTAREA NAME="Input" Rows=3 Cols=70></TEXTAREA><BR>

<FONT SIZE=5 COLOR=#995599>Output:</FONT><BR>
<TEXTAREA NAME="Out" Rows=5 Cols=70></TEXTAREA>

<BR><BR>
<OBJECT ID="ActiveML" WIDTH=500 HEIGHT=300 CLASSID="CLSID:C06D7B50-B613-11D2-81BB-00400535F9E7">
</OBJECT>
</CENTER>

</BODY>
</HTML>

Execute the code or read it from Internet Explorer, and you get:

@

Press [Connect] and the control will be connected to the kernel. Type your command in the [Input] box. Press [Evaluate], and you get its result in the [Output] box.

@

Images can be displayed on the control. If you invoke a Plot command, you get a graph on the control.

@

If the DisplayTextQ property is true, evaluation results are displayed also on the control.

By pressing [Disconnect], the link to the kernel is disconnected.

Known bug

The control cannot handle special characters and characters other than ASCII.

Reference

Visual Basic sample program gMini FrontEndh included in MathLink Developerfs Kits.