Search Results for

    Show / Hide Table of Contents

    The simplest example of scripting

    Here is a sample code which demonstrates the easiest way of using FastScript. Just put the TfsScript, TfsPascal and TButton components onto your form and write the following code in the button.OnClick event:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      fsScript1.Clear;
      fsScript1.Lines.Text :=  'begin ShowMessage(''Hello!'') end.';
      fsScript1.Parent := fsGlobalUnit;
      fsScript1.SyntaxType := 'PascalScript';
      if not fsScript1.Run then
        ShowMessage(fsScript1.ErrorMsg); 
    end;
    
    • Clear the script. It is necessary if you use one component to run many scripts.
    • Fill the Lines property by the script code;
    • To use standard types and functions pass the fsGlobalUnit to the Parent property.
    • Run the script using the PascalScript language. If compilation was successful, Run method returns True. Otherwise an error message is shown.

    Another way to use TfsScript without fsGlobalUnit (for example, in multi-thread environment):

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      fsScript1.Clear;
      fsScript1.AddRTTI;
      fsScript1.Lines.Text :=  'begin ShowMessage(''Hello!'') end.';
      fsScript1.SyntaxType := 'PascalScript';
      if not fsScript1.Run then
        ShowMessage(fsScript1.ErrorMsg); 
    end;
    
    Back to top © Copyright Fast Reports Inc.