Search Results for

    Show / Hide Table of Contents

    TfsScript component

    TfsScript component

    This is a main scripting component.

    Properties:

    SyntaxType: String;

    The type of the script language. By default four types of scripts are supported: "PascalScript", "C++Script", "BasicScript", "JScript". Warning! The property has the string type and it is easy to make a mistake in the syntax type indication. The value by default is “PascalScript”.

    Lines: TStrings;

    A script text. Contains strings of the script.

    Methods:

    function Compile: Boolean;
    

    Compiles the source code. Source code must be placed in the TfsScript.Lines property before you call the Compile method.

    procedure Execute;
    

    Execute script after compiling.

    function Run: boolean;
    

    Compile and execute script. Returns true if compile was successful. This method is the analogue to the Compile + Execute.

    Examples of use:

    Example1.

    Delphi. Loads script file MyTestScript.pas and execute it.

    fsScript1.Lines.LoadFromFile(‘MyTestScript.pas’);
    if fsScript1.Compile then
       fsScript1.Execute
    else
       ShowMessage(‘Script compilation error!’);
    

    Example2. Delphi. Pressing the Button1 gives the strings from fsSyntaxMemo1 component to fsScript1.Lines and execute script.

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      fsScript1.Lines := fsSyntaxMemo1.Lines;
      if not fsScript1.Run then
         ShowMessage(‘Script compilation error!’);
    end;
    

    Example3. Delphi. Loads “C++Script” from MyTestScript.cpp file and execute it.

    fsScript1.Lines.LoadFromFile(‘MyTestScript.cpp’);
    fsScript1.SyntaxType := ‘C++Script’;
    if fsScript1.Compile then
       fsScript1.Execute
    else
       ShowMessage(‘Script compilation error!’);
    

    Example4. С++Builder IDE. Loads “C++Script” from MyTestScript.cpp file and execute it.

    fsScript1->Lines->LoadFromFile(‘MyTestScript.cpp’);
    fsScript1->SyntaxType = “C++Script”;
    if (fsScript1->Compile()) 
       fsScript1->Execute();
    else
       ShowMessage(“Script compilation error!”);
    
    Back to top © Copyright Fast Reports Inc.