TPaxScripter Methods


TPaxScripter.AddBreakpoint

Adds breakpoint to a script.
function AddBreakpoint(const ModuleName: String; LineNumber: Integer;
const Condition: String = ''; PassCount: Integer = 0): Boolean;

Arguments

ModuleName
Name of module.
LineNumber
Line number.
Condition
Specifies a conditional expression that is evaluated each time the breakpoint is encountered. Program execution stops when the expression evaluates to true. Enter a conditional expression to stop program execution.
PassCount
Stops program execution at a certain line number after a specified number of passes.

Example

PAXScripter1.AddBreakpoint('MyModule', 17);

See Also

TPaxScripter.AddCode

Adds source code to a module.
procedure AddCode(const ModuleName, Code: String);

Arguments

Module
A module name.
Code
Source code.

Example

PAXScripter1.AddModule('MyModule', 'paxBasic'); 
PAXScripter1.AddCode('MyModule', 'Dim X = 10');

See Also

TPaxScripter.AddCodeFromFile

Adds source code to scripter from a text file.
procedure AddCodeFromFile(const ModuleName, FileName: String);

Arguments

ModuleName
Name of module.
FileName
Name of text file

Example

PAXScripter1.AddModule('MyModule', 'paxC');
PAXScripter1.AddCodeFromFile('MyModule', 'afile.sc');

See Also

TPaxScripter.AddDelphiForm

Adds a Delphi form to script project.
procedure AddDelphiForm(const DfmFileName, UnitFileName: String); overload;
procedure AddDelphiForm(const ModuleName: String; Dfm, Source: TStream); overload;

See Also

TPaxScripter.AddModule

Adds a new module to scripter.
function AddModule(const ModuleName, LanguageName: String): Integer;

Arguments

ModuleName
Name of module.
Language name
Name of language

The AddModule method returns id of module.

Example

ModuleId := PAXScripter1.AddModule('MyModule', 'paxC');

See Also

TPaxScripter.CallFunction

Calls a script-defined function or method of object defined in the global (noname) namespace.
function CallFunction(const Name: String; const Params: array of const; const ObjectName: String = ''): Variant;

Arguments

Name
Name of function or procedure.
Params
List of actual parameters.
ObjectName
Name of host-defined object or script-defined object. If ObjectName = '', CallFunction calls function defined in the global (noname) namespace.

The CallFunction calls CallFunctionByID internally.

Example

// Script in paxPascal:

uses
  StdCtrls, ExtCtrls, Forms;

type
  TMyForm = class(TForm)
   public
     Memo: TMemo;
     pnl: TPanel;
     b1: TButton;
     constructor Create(Owner: TComponent);
     procedure OnPress( Sender );
   end;

procedure TMyForm.OnPress( Sender );
begin   
  Memo.Lines.Add( 'World' );
end;

constructor TMyForm.Create(Owner: TComponent);
begin
  inherited;
  Top := 100;
  Left := 200;
  Caption := 'MyForm';

  Memo := TMemo.Create(Self);
  Memo.Parent := Self;
  Memo.Width := 100;
  Memo.Align := 'alClient';

  pnl := TPanel.Create(Self);
  pnl.Parent := Self;
  pnl.Align := 'alBottom';
  pnl.Height := 50;

  b1:= TButton.Create(Self);
  b1.Parent := pnl;
  b1.SetBounds( 10, 10, 50, 20 );
  b1.Caption := 'Press';
  b1.OnClick := @ OnPress;
end;

var
  F: TMyForm;
begin
  F := TMyForm.Create(nil);
  F.Memo.Lines.Add( 'Hello' );
  F.Show;
end.

...........................

Delphi code:

 PaxScripter1.CallFunction("TMyForm.OnPress", [Sender], "F");

C++ Builder code:

 TVarRec v[] = { Sender };
 PaxScripter1->CallFunction("TMyForm.OnPress", v, ARRAYSIZE(v) - 1, "F");

See Also

TPaxScripter.CallFunctionEx

Calls a script-defined function or method of object defined in the global (noname) namespace.
function CallFunctionEx(const Name: String; const Params: array of const; const StrTypes: array of String; AnObjectName: String = ''): Variant;

The method has the same semantics as CallFunction, but, in addition, allows you to provide information about actual parameter types. Use CallFunctionEx instead of Use CallFunction when you want to pass an interface pointer as parameter.

See Also

TPaxScripter.CallFunctionByIdEx

Calls a script-defined function represented by its id.
function CallFunctionByIDEx(SubID: Integer; const Params: array of const; const StrTypes: array of String; ObjectID: Integer = 0): Variant;

The method has the same semantics as CallFunctionById, but, in addition, allows you to provide information about actual parameter types. Use CallFunctionByIdEx instead of Use CallFunctionById when you want to pass an interface pointer as parameter.

See Also

TPaxScripter.CallFunctionByID

Calls a script-defined function represented by its id.
function CallFunctionByID(SubID: Integer; const Params: array of const; ObjectID: Integer = 0): Variant;

Arguments

SubID
Id of function.
Params
Array of parameters
ObjectID
Id of a object.

Example

S := TPaxScripter.Create(nil);
S.AddLanguage(TPaxPascal.Create(nil));
S.AddModule('1', 'paxPascal');
S.AddCode('1', 'program Demo;');
S.AddCode('1', 'Var D : array[0..1023] of double;');
S.Addcode('1', 'procedure Init;');
S.Addcode('1', 'begin');
S.Addcode('1', 'D[0] := 1;');
S.Addcode('1', 'end;');
S.Addcode('1', 'function P(TimeIndex : integer; MinSize, MaxSize:double) : double;');
S.AddCode('1', 'begin');
S.AddCode('1', ' D[0] := D[0] + 1;'); 
S.AddCode('1', ' P := D[0];');
S.AddCode('1', 'end;');
S.AddCode('1', 'begin');
S.AddCode('1', 'end.');
S.Compile;
S.CallFunction('Demo.Init', []);

SubID := GetMemberID('Demo.P');

for i := 0 to 1000 do
begin
  S.AddBreakpoint('1', 10);
  S.CallFunctionByID(SubID, [100, 0.1, 0.2]);
  Assert(S.ScripterState = ssPaused);
  assert(S.CallStack.Count = 1);
  S.Eval('D[0]', 'paxPascal', Res);
  D1 := Res;
  assert(round(D1) = (i + 2));
  S.RemoveBreakpoint('1', 10);
  S.Run(rmrun, '', 0);
  Assert(S.ScripterState = ssTerminated);
end;

See Also

TPaxScripter.Compile

Compiles all modules or performs the syntax check.
function Compile(SyntaxCheckOnly: Boolean = false): Boolean;

Arguments

SyntaxCheckOnly
If value is false, paxScript compiles all modules, otherwise it performs the syntax check only.

Example

AddModule('PascalModule', 'paxPascal');
AddModule('BasicModule', 'paxBasic');
AddCodeFromFile('PascalModule', 'pascal_module.sp');
AddCode('BasicModule', 'Dim X = [10, 20, 30]');
AddCode('BasicModule', 'Dim Y = 80');
Compile;

See Also

TPaxScripter.CompileModule

Compiles a module or performs the syntax check.
function CompileModule(const ModuleName: String;
          SyntaxCheckOnly: Boolean = false): Boolean;

Arguments

ModuleName
Name of module.
SyntaxCheckOnly
If value is true, paxScript compiles module, otherwise it performs the syntax check only.

Example

PAXScripter1.AddModule('MyModule', 'paxPascal');
PAXScripter1.AddCodeFromFile('MyModule', 'afile.sp');
PAXScripter1.CompileModule('MyModule');

See Also

TPaxScripter.Create

Creates and initializes a TPaxScripter instance.
constructor Create(AOwner: TComponent); override;

TPaxScripter.Destroy

Destroys an instance of TPAXScripter.
destructor Destroy; override;

TPaxScripter.DiscardError

Descards last error raised at compile-time or run-time.
procedure DiscardError;

See Also

TPaxScripter.EnumMembers

Eumerates members of script defined class or fields of script-defined method.
procedure EnumMembers(ID: Integer;
                      Module: Integer;
                      CallBack: TPaxMemberCallback;
                      Data: Pointer);

Arguments

ID
Id of class or method
Module
Id of module (0, 1, 2...).
CallBack
Call back function which is called for each member.

TPaxMemberCallback = procedure (const Name: String; ID: Integer; Kind: TPAXMemberKind; ml: TPAXModifierList; Data: Pointer) of object;

  • Name - name of member
  • ID - id of member
  • Kind - kind of member; TPAXMemberKind = (mkUnknown, mkConst, mkField, mkProp, mkParam, mkResult, mkMethod, mkClass, mkStructure, mkEnum)
  • ml - modifier list; TPAXModifier = (modDEFAULT, modPUBLIC, modPRIVATE, modSTATIC, modPROTECTED); TPAXModifierList = set of TPAXModifier;
  • Data - user-defined pointer
Data
User-defined pointer.

Group: "Code explorer".

TPaxScripter.Eval

Evaluates an expression at run-time.
function Eval(const Expression, LanguageName: String; var Res: Variant): Boolean;

Arguments

Expression
An expression.
LanguageName
Name of pax language
Res
Result value.

Function Eval returns false, if there was a compile-time or run-time error. Use Eval function to process the watch expressions at run-time.

Example

PAXScripter1.Eval('x[10]', 'paxPascal', Res);

See Also

TPaxScripter.FileExtToLanguageName

Returns name of language by a file name.
function FileExtToLanguageName(const FileExt: String): String;

Example

S PaxScripter1.FileExtToLanguageName('.pb');
if S <> nil then
  ShowMessage(Format('Scripts of %s language are located in files which have extension %s', [S, '.pb']);

TPaxScripter.FindLanguage

Returns instance of TPaxLanguage class which represents properties of a scripting language.
function FindLanguage(const LanguageName: String): TPaxLanguage;

If scripter does not support the language, the FindLanguage method returns nil.

Example

L := PaxScripter1.FindLanguage('paxBasic'); 
if L <> nil then
  ShowMessage('Ok')
else
  ShowMessage('This TPaxScripter instance does not support the paxBasic language');

TPaxScripter.GetAddress

Returns address of variable or method.
function GetAddress(ID: Integer): Pointer;

TPaxScripter.GetClassInfo

Allows you to get information about methods, fields, properties and events of a class.
procedure GetClassInfo(const FullName: String; mk: TPaxMemberKind; L: TStrings);

Arguments

FullName
Full qualified name of class.
mk
Admissible values are mkField, mkProp, mkMethod, mkEvent.
L
Output string list.

TPaxScripter.GetInstruction

Returns p-code instruction.
function GetInstruction(N: Integer): TPaxInstruction;

TPaxInstruction = record N, Op, Arg1, Arg2, Res: Integer; end;

See Also

TPaxScripter.GetKind

Returns kind of id.
function GetKind(ID: Integer): TPAXMemberKind;

TPAXMemberKind = (mkUnknown, mkConst, mkField, mkProp, mkParam, mkResult, mkMethod, mkClass, mkStructure, mkEnum);

TPaxScripter.GetLastResult

Returns id of result of function which was called in the debug mode.
function GetLastResult: Integer;

TPaxScripter.GetMemberID

Returns id of a script-defined variable, method or type by its name.
function GetMemberID(const Name: String): Integer;

Group: "Code explorer".

TPaxScripter.GetModule

Returns id of module.
function GetModule(ID: Integer): Integer;

Modules are numerated by numbers 0, 1, 2... according to the order of AddModule method calls.

See Also

TPaxScripter.GetName

Returns name of script-defined variable, method or class represented by its id.
function GetName(ID: Integer): String;

Group: "Code explorer".

TPaxScripter.GetOwnerID

Returns id of owner of script-defined type, variable or method.
function GetOwnerID(ID: Integer): Integer;

TPaxScripter.GetParamID

Returns id of formal parameter of a script-defined method.
function GetParamID(SubID, ParamIndex: Integer): Integer;

Group: "Code Explorer".

TPaxScripter.GetPosition

Returns text position of a script-defined variable, method or type by its id.
function GetPosition(ID: Integer): Integer;

Group: "Code Explorer".

TPaxScripter.GetResultID

Returns id of result of script-defined method.
function GetResultID(SubID: Integer): Integer;

Group: "Code explorer".

TPaxScripter.GetRootID

Returns id of noname namespace.
function GetRootID: Integer;

Group: "Code explorer".

TPaxScripter.GetTypeID

Returns id of type of a script-defined variable or method.
function GetTypeID(ID: Integer): Integer;

Group: "Code explorer".

TPaxScripter.GetUserData

Returns user data associated with a host-defined variable, constant, type or method.
function GetUserData(ID: Integer): Integer;

TPaxScripter.GetValueByID

Returns value of a script-defined variable by its id.
function GetValueByID(ID: Integer): Variant;

See Also

TPaxScripter.InstructionCount

Returns number of instructions of p-code.
function InstructionCount: Integer;

See Also

TPaxScripter.IsError

Returns true, if there was an error at compile-time or run-time.
function IsError: Boolean;

See Also

TPaxScripter.IsExecutableSourceLine

Returns 'true', if line of source code is the executable script line.
function TPaxScripter.IsExecutableSourceLine(const ModuleName: String; L: Integer): Boolean;

Example

PaxScripter1.ResetScripter;
  PaxScripter1.AddModule('1', 'PaxPascal');
  PaxScripter1.AddCode('1', Memo1.Lines.Text);
  PaxScripter1.Compile();

  Memo2.Lines.Clear;

  L := TStringList.Create;
  L.Text := Memo1.Text;

  for I:=0 to L.Count - 1 do
  begin
    if PaxScripter1.IsExecutableSourceLine('1', I) then
      S := '*  ' + L[I]
    else
      S := '   ' + L[I];
    L[I] := S;
  end;

  Memo2.Text := L.Text;

  L.Free;

TPaxScripter.IsLocalVariable

Returns true, if id represents a local variable.
function IsLocalVariable(ID: Integer): Boolean;

TPaxScripter.LanguageCount

Returns number of pax-languages which supports the paxScripter.
function LanguageCount: Integer;

Example

for I:=0 to PaxScripter1.LanguageCount - 1 do
  ShowMessage(PaxScripter1.Languages[I].LanguageName);

TPaxScripter.LoadProject

Loads paxScript project from disk.
procedure LoadProject(const FileName: String);

Example

PaxScripter1.LoadProject('myproject.pax');

See Also

TPaxScripter.LoadFromFile

Loads all modules of compiled script from a file.
procedure LoadFromFile(const FileName: String);

See Also

TPaxScripter.LoadFromStream

Loads all modules of compiled script from a stream.
procedure LoadFromStream(S: TStream);

Example

var
  S: TPaxScripter;
  F: TFileStream;
begin
  F := TFileStream.Create('compiled_script.bin', fmOpenRead);
  S := TPaxScripter.Create(nil);
  try
    S.LoadFromStream(F);
    S.Run;
  finally
    S.Free;
    F.Free;
  end;
end;

See Also

TPaxScripter.RegisterConstant

Adds a host-defined constant to a script.
procedure RegisterConstant(const Name: String; Value: Variant; Owner: Integer = -1);

Arguments

Name
Name of constant.
Value
Value of constant.
Owner
Optional. Determines handle of namespace which contains the constant.

Example 1

PAXScripter1.RegisterConstant('MyConst', 89.45);

Example 2

RegisterConstant('X', 800, RegisterNamespace('MyNamespace'));

See Also

TPaxScripter.RegisterInterfaceVar

Allows you to register a variable of interface type.
procedure RegisterInterfaceVar(const Name: String; PIntf: PUnknown; const guid: TGUID; Owner: Integer = -1);

Arguments

Name
Name of variable
PIntf
Pointer to the variable.
Guid
GUID of the interface type.

Example

private
  { Private declarations }
  hostobj: ITest;
..............................................................
PaxScripter1.RegisterInterfaceVar('hostobj', @ hostobj, ITest);

TPaxScripter.RegisterLanguage

Registeres new TPaxLanguage instance to scripter.
procedure RegisterLanguage(L: TPaxLanguage);

Use AddLanguage method call to register new pax-language for scripter.

Example

S := TPaxScripter.Create(nil);
L := TPaxPascal.Create(nil);
S.RegisterLanguage(L);
S.AddModule('1', 'paxPascal');
S.AddCode('1', 'print "Hello";');
S.Run;
S.Free;
L.Free;

Note, you need no to use RegisterLanguage in a GUI application as TPaxScripter will register all pax-languages components automatically. (These components should has the same owner that given TPaxScripter instance has).

See Also

TPaxScripter.RegisterVariable

Adds a host-defined variable to a script.
procedure RegisterVariable(const Name, TypeName: String; Address: Pointer; Owner: Integer = -1);

Arguments

Name
Name of variable.
TypeName
Any scalar Delphi type.
Address
Address of variable.
Owner
Optional. Determines handle of namespace which contains the variable.

Example 1

RegisterVariable('MyVar', 'Integer', @MyVar);

Example 2

RegisterVariable('X', 'Doubler', @X, RegisterNamespace('MyNamespace'));

See Also

TPaxScripter.RegisterObject

Adds a host-defined object to a script.
procedure RegisterObject(const Name: String; Instance: TObject; Owner: Integer = -1);

Arguments

Name
Name of object.
Instance
Object instance.
Owner
Optional. Determines handle of namespace which contains the object.

Example 1

MyObject := TMyObject.Create;
PAXScripter1.RegisterObject('MyObject', MyObject);

Example 2

MyObject := TMyObject.Create;
PAXScripter1.RegisterObject('MyObject', MyObject, RegisterNamespace('MyNamespace'));

See Also

TPaxScripter.RegisterField

Allows to assign address of field of a script-defined structure.
procedure RegisterField(const ObjectName: String;
                        ObjectType: String;
                        FieldName: String;
                        FieldType: String;
                        Address: Pointer);

Example

// Delphi code

var MyHostDefinedVariable: Integer;
begin
MyHostDefinedVariable := 100;
RegisterField('P', 'TPoint', 'X', 'Integer', @MyHostDefinedVariable);
................

// Script code

type
  TPoint = record
    X, Y: Integer;
  end;

var P: TPoint;
print P.X; // outputs 100

TPaxScripter.RemoveAllBreakpoints

Removes all breakpoints from a script.
procedure RemoveAllBreakpoints;

Example

with PAXScripter1 do
begin
  RemoveAllBreakpoints;
  AddBreakpoint('MyModule', 17);
  AddBreakpoint('MyModule', 32);
  Run(rmStepOver);
end;

See Also

TPaxScripter.RemoveBreakpoint

Removes breakpoint from a script.
function AddBreakpoint(const ModuleName: String; LineNumber: Integer): Boolean;

Arguments

ModuleName
Name of module.
LineNumber
Line number.

Example

PAXScripter1.RemoveBreakpoint('MyModule', 17);

See Also

TPaxScripter.ResetScripter

Removes all modules and disconnect registered objects from scripter.
procedure ResetScripter;

Example

var
  S: TPaxScripter;
begin
  S := TPaxScripter.Create(nil);

  S.RegisterObject('Object1', FormMain);

  S.AddModule('main', 'paxPascal');
  S.AddCodeFromFile('main', 'script1.txt');
  S.Run;

  S.ResetScripter;

  S.RegisterObject('Object2', FormMain.Button1);

  S.AddModule('main', paxPascal);
  S.AddCodeFromFile('main', 'script2.txt');
  S.Run;
....................

TPaxScripter.Run

Runs script.
procedure Run(RunMode: Integer = rmRun; const ModuleName: String = ''; LineNumber: Integer = 0);

Arguments

RunMode
Determines a run mode.
  • rmRun = 0. Executes a script.
  • rmStepOver = 1. Executes a script one line at a time, stepping over procedures while executing them as a single unit.
  • rmTraceInto = 2. Execute a script one line at a time, tracing into procedures and following the execution of each line.
  • rmRunToCursor = 3. Executes a script up to the location of the cursor which is specified by ModuleName and LineNumber.
  • rmTraceToNextSourceLine = 4. Stops on the next source line in your application, regardless of the control flow.
ModuleName
It is used only for RunMode = rmRunToCursor. Specifies module name of the cursor.
LineNumber
It is used only for RunMode = rmRunToCursor. Specifies the source code line number of the cursor.

Example

PAXScripter1.Run(rmRunToCursor, 'MyModule', 15);

See Also

TPaxScripter.RunInstruction

Runs current instruction of p-code.
procedure RunInstruction;

Example

unit TestThread1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, PaxScripter, PaxPascal;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    cbStop: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    fThreadCount: Integer;
  public
    { Public declarations }
  end;

 TMyThread = class(TThread)
 private
   Scripter: TPaxScripter;
   Language: TPaxPascal;
   UnsafeInstructions: array[1..100] of Boolean;
   procedure MarkInstructions;
   procedure InvokeInstruction;
   procedure InstructionHandler(Sender: TObject; N: Integer;
                                var Handled: Boolean);
 public
   constructor Create;
   destructor Destroy; override;
   procedure Execute; override;
 end;

var
  Form1: TForm1;

implementation

uses
  IMP_SysUtils, IMP_Classes, IMP_StdCtrls, IMP_Controls, IMP_Forms, IMP_Graphics;

{$R *.DFM}

constructor TMyThread.Create;
begin
  inherited create(True);
  FreeOnTerminate := true;
  InterlockedIncrement(Form1.fThreadCount);
  resume;
end;

destructor TMyThread.Destroy;
begin
  InterlockedDecrement(Form1.fThreadCount);
  inherited;
end;

procedure TMyThread.MarkInstructions;
var
  N: Integer;
  S: String;
  Instruction: TPaxInstruction;
begin
  for N:=1 to Scripter.InstructionCount do
  begin
    UnsafeInstructions[N] := false;
    Instruction := Scripter.GetInstruction(N);
    if Instruction.Op = _OP_CALL then
    begin
      S := Scripter.GetName(Instruction.Arg1);
      if S = 'TextOut' then
        UnsafeInstructions[N] := true;
    end;
  end;
end;

procedure TMyThread.InvokeInstruction;
begin
  Scripter.RunInstruction;
end;

procedure TMyThread.InstructionHandler(Sender: TObject; N: Integer;
                                       var Handled: Boolean);
begin
  if UnsafeInstructions[N] then
  begin
    Synchronize(InvokeInstruction);
    Handled := true;
  end;
end;

procedure TMythread.Execute;
begin
  while not form1.cbStop.Checked do
  try
    Scripter := TPaxScripter.Create(nil);
    Language := TPaxPascal.Create(nil);
    try
      Scripter.RegisterLanguage(Language);
      Scripter.RegisterObject('Form1', Form1);
      Scripter.RegisterVariable('ThreadCount', 'Integer', @Form1.fThreadCount);

      Scripter.AddModule('1', Language.LanguageName);
      Scripter.AddCode('1', 'uses SysUtils, Classes, StdCtrls, Controls, Forms, Graphics;');
      Scripter.AddCode('1','Form1.Memo1.Lines.Add(IntToStr(ThreadCount));');
      Scripter.AddCode('1','Form1.Canvas.TextOut(0, 0, IntToStr(ThreadCount));');

      Scripter.Compile;
      MarkInstructions;

      Scripter.OnRunning := InstructionHandler;
      Scripter.Run;
      if Scripter.IsError then
        raise Exception.create(Scripter.ErrorDescription);
    finally
      FreeAndNil(Language);
      FreeAndNil(Scripter);
    end;
  except
    Application.HandleException(self);
    terminate;
    break;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  cbStop.Checked := false;
  for I:=1 to 1 do
    TMyThread.Create;
  while fThreadCount > 0 do
    Application.ProcessMessages;
  Memo1.Lines.Add('Finished');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterClassType(TForm1, -1);
end;

end.

See Also

TPaxScripter.SaveModuleToFile

Saves a module of compiled script to a file.
procedure SaveModuleToFile(const ModuleName, FileName: String);

Example

var
  S: TPaxScripter;
  LangPascal: TPaxPascal;
  LangBasic: TPaxBasic;
  LangC: TPaxC;
begin
/////// CREATE COMPILED MODULES //////////////////////

  S := TPaxScripter.Create(nil);

  LangPascal := TPaxPascal.Create(nil);
  LangC := TPaxC.Create(nil);
  LangBasic := TPaxBasic.Create(nil);
  S.RegisterLanguage(LangPascal);
  S.RegisterLanguage(LangC);
  S.RegisterLanguage(LangBasic);

  S.AddModule('0', LangPascal.LanguageName);
  S.AddCode('0', 'const A = 17;');
  S.AddCode('0', 'const B = 10 + A;');

  S.AddModule('1', LangC.LanguageName);
  S.AddCode('1', 'void P(x){ print x; }');

  S.AddModule('2', LangBasic.LanguageName);
  S.AddCode('2', 'Imports Classes, Forms');
  S.AddCode('2', 'Class MyForm');
  S.AddCode('2', '  Inherits TForm');
  S.AddCode('2', '  Sub New(Owner As TComponent)');
  S.AddCode('2', '     Me = MyBase.Create(Owner)');
  S.AddCode('2', '     Caption = "MyForm"');
  S.AddCode('2', '  End Sub');
  S.AddCode('2', 'End Class');

  S.Compile;

  S.SaveModuleToFile('0', 'u0.bin');
  S.SaveModuleToFile('1', 'u1.bin');
  S.SaveModuleToFile('2', 'u2.bin');

  S.Free;

  LangPascal.Free;
  LangC.Free;

/////// USE COMPILED MODULES /////////////////////////

  S := TPaxScripter.Create(nil);

  LangBasic := TPaxBasic.Create(nil);
  S.RegisterLanguage(LangBasic);

  // add a source code module
  S.AddModule('one', 'paxBasic');
  S.AddCode('one', 'Dim F As MyForm');
  S.AddCode('one', 'F = New MyForm(NULL)');
  S.AddCode('one', 'F.Show()');
  S.AddCode('one', 'print A');
  S.AddCode('one', 'print B');
  S.AddCode('one', 'P(300)');

  // add compiled modules in a random order
  S.LoadFromFile('u1.bin');
  S.LoadFromFile('u0.bin');
  S.LoadFromFile('u2.bin');

  S.Run;

  S.Free;
  LangBasic.Free;
end;

See Also

TPaxScripter.SaveModuleToStream

Saves a module of compiled script to a stream.
procedure SaveModuleToStream(const ModuleName: String; S: TStream);

See Also

TPaxScripter.SaveToFile

Saves all modules of compiled script to a file
procedure SaveToFile(const FileName: String);

See Also

TPaxScripter.SaveToStream

Saves all modules of compiled script to a stream.
procedure SaveToStream(S: TStream);

Example

var
  S: TPaxScripter;
  F: TFileStream;
begin
  F := TFileStream.Create('compiled_script.bin', fmCreate);
  S := TPaxScripter.Create(nil);
  try
    S.AddModule('main', 'paxPascal');
    S.AddCodeFromFile('main', 'myscript.txt');
    S.Compile;
    S.SaveToStream(F);
  finally
    S.Free;
    F.Free;
  end;
end;

See Also

TPaxScripter.SetValueByID

Assigns value of a script-defined variable by its id.
procedure SetValueByID(ID: Integer; const Value: Variant);

See Also

TPaxScripter.UnregisterAllConstants

Unregisteres all host-defined constants once registered by RegisterConstant method.
procedure UnregisterAllConstants;

TPaxScripter.UnregisterAllObjects

Unregisteres all host-defined objects once registered by RegisterObject method.
procedure UnregisterAllObjects;

TPaxScripter.UnregisterAllVariables

Unregisteres all host-defined variables once registered by RegisterVariable method.
procedure UnregisterAllVariables;

TPaxScripter.UnregisterConstant

Unregisteres a host-defined constant once registered by RegisterConstant method.
procedure UnregisterConstant(const Name: String; Owner: Integer = -1);

TPaxScripter.UnregisterLanguage

Unregisteres pax-language for given TPaxScripter instance.
procedure UnregisterLanguage(const LanguageName: String);

See Also

TPaxScripter.UnregisterObject

Unregisteres a host-defined object once registered by RegisterObject method.
procedure UnregisterObject(const Name: String; Owner: Integer = -1);

TPaxScripter.UnregisterVariable

Unregisteres a host-defined variable once registered by RegisterVariable method.
procedure UnregisterVariable(const Name: String; Owner: Integer = -1);

Copyright © 1999-2006 VIRT Laboratory. All rights reserved.