First Scripting Application

Top  Previous  Next

Here you can find a walk-though for creating a simple application capable of running VBScript scripts.

Let's suppose that there'll be Main procedure in the script which will accept two integers num1 and num2, and return their sum which will then be displayed to a user (see code sample below).


The following steps have to be performed to create the application:


1.Create new Vcl Forms application; add a TMemo control - Memo1; Assign the following script procedure code to its Lines property:

Sub Main(num1, num2)

  res = num1 + num2

  MsgBox res

End Sub



2.Create the TLMDScriptControl component LMDScriptControl1; set its Language property to slVBScript;


3.Create some 'run it' control, e.g. a button Button1; create its OnClick event handler which should contain the code for assigning script code to Source property of LMDScriptControl1, setting its Active property to True and calling Main procedure declared in the script (passing parameters to it as a variant array):



procedure TForm1.Button1Click(Sender: TObject);


  LMDScriptControl1.Source := Memo1.Lines;



    LMDScriptControl1.RunProc('Main', [37]);






4.Click 'Run' button and fun! Here is the result: