Quick start

Top  Previous  Next

  Here is a sample code which demonstrates the easiest way of using FastScript. For the correct work of the example put the components fsScript1: TfsScript and fsPascal1: TfsPascal on the form .

 

uses FS_iInterpreter;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

 fsScript1.Clear; // do this if you running many scripts from one component

 fsScript1.Lines.Text := 'begin ShowMessage(''Hello!'') end.';

 fsScript1.Parent := fsGlobalUnit; // use standard classes and methods

 fsScript1.SyntaxType := 'PascalScript';

 if fsScript1.Compile then

   fsScript1.Execute else  

   ShowMessage(fsScript1.ErrorMsg);

end;

 

  As you can see, there is nothing difficult here. At first we fill in the fsScript1.Lines property with the script text. For using standard types and functions we set Parent property to the fsGlobalUnit. Then we compile the script using PascalScript language (you can use C++Script, BasicScript, JScript as well). If compilation is successful Compile method returns True and we can Execute the script. Otherwise the error message is shown.