Allows you to call a shared method of a script-defined class.function CallClassMethod(const FullName: String; Instance: TClass; const ParamList: array of OleVariant): OleVariant;
Allows you to invoke an instance method of a script-defined class.function CallMethod(const FullName: String; Instance: TObject; const ParamList: array of OleVariant): OleVariant;
Allows you to invoke a script-defined routine.function CallRoutine(const FullName: String; const ParamList: array of OleVariant): OleVariant;
Constructor of TPaxProgram class.constructor Create(AOwner: TComponent); override;
Destructor of TPaxProgram class.destructor Destroy; override;
Terminates a paused program.procedure DiscardPause;
Returns address of a script-defined variable, procedure or function.function GetAddress(Handle: Integer): Pointer; function GetAddress(const FullName: String): Pointer;Arguments
HandleId of a a script-defined variable, procedure or function.
Example
// declare procedural type that conforms to a script-defined procedure type TProcP = procedure (X: Integer); stdcall; procedure TForm1.Button1Click(Sender: TObject); var H_Y, H_P: Integer; I: Integer; P: Pointer; begin PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); H_Y := PaxCompiler1.RegisterVariable(0, 'Y', _typeINTEGER); PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName); PaxCompiler1.AddCode('1', 'procedure P(X: Integer);'); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', ' Y := Y + X;'); PaxCompiler1.AddCode('1', 'end;'); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', 'end.'); if PaxCompiler1.Compile(PaxProgram1) then begin H_P := PaxCompiler1.GetHandle(0, 'P', true); P := PaxProgram1.GetAddress(H_P); // get address of script-defind procedure PaxProgram1.SetAddress(H_Y, @Y); PaxProgram1.Init; // init procedure call TProcP(P)(10); // call it ShowMessage(IntToStr(Y)); end else for I:=0 to PaxCompiler1.ErrorCount do ShowMessage(PaxCompiler1.ErrorMessage[I]); end;
Returns size of image of compiled program.function GetImageSize: Integer;
Returns type information of a script-defined type.function GetTypeInfo(const FullTypeName: String): PTypeInfo;
Returns 'true', if script is in the paused state.function IsPaused: Boolean;
Returns 'true', if component runs a program.function IsRunning: Boolean;
Binds an instance of script-defined class with dfm file.procedure LoadDFMFile(Instance: TObject; const FileName: String);
Binds an instance of a script-defined class with dfm stream.procedure LoadDFMStream(Instance: TObject; S: TStream);
Loads program from a file.procedure LoadFromFile(const Path: String);
Example
var PaxProgram1: TPaxProgram; begin if FileExists('1.bin') then begin PaxProgram1 := TPaxProgram.Create(nil); try PaxProgram1.LoadFromFile('1.bin'); PaxProgram1.Run; finally PaxProgram1.Free; end; end; end;
Loads program from a stream.procedure LoadFromStream(S: TStream);
Pauses script.procedure Pause;
Resumes a paused script.procedure Resume;
Executes program.procedure Run;
Example
procedure TForm1.Button1Click(Sender: TObject); var H_ShowMessage: Integer; I: Integer; begin PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); // register routine 'ShowMessage' H_ShowMessage := PaxCompiler1.RegisterRoutine(0, 'ShowMessage', _typeVOID, _ccREGISTER); PaxCompiler1.RegisterParameter(H_ShowMessage, _typeSTRING, _Unassigned); PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', ' ShowMessage(''Hello'');'); PaxCompiler1.AddCode('1', 'end.'); if PaxCompiler1.Compile(PaxProgram1) then begin // set address of routine 'ShowMessage' PaxProgram1.SetAddress(H_ShowMessage, @ShowMessage); PaxProgram1.Run; end else for I:=0 to PaxCompiler1.ErrorCount - 1 do ShowMessage(PaxCompiler1.ErrorMessage[I]); end;
Saves program to a binary file.procedure SaveToFile(const Path: String);
Saves program to a stream.procedure SaveToStream(S: TStream);
Sets address of a host-defined variable, procedure or function.procedure SetAddress(Handle: Integer; P: Pointer);Arguments
HandleId of a host-defined variable, procedure or function.PAddress
Example
type TMyPoint = packed record x, y: Integer; end; procedure TForm1.Button1Click(Sender: TObject); var H_TMyPoint, H_MyPoint: Integer; MyPoint: TMyPoint; I: Integer; begin MyPoint.X := 60; MyPoint.Y := 23; PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); // register host-defined type H_TMyPoint := PaxCompiler1.RegisterRecordType(0, 'TMyPoint'); PaxCompiler1.RegisterRecordTypeField(H_TMyPoint, 'X', _typeINTEGER); PaxCompiler1.RegisterRecordTypeField(H_TMyPoint, 'Y', _typeINTEGER); // register host-defined variable H_MyPoint := PaxCompiler1.RegisterVariable(0, 'MyPoint', H_TMyPoint); PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', ' MyPoint.Y := 8;'); PaxCompiler1.AddCode('1', 'end.'); if PaxCompiler1.Compile(PaxProgram1) then begin PaxProgram1.SetAddress(H_MyPoint, @MyPoint); PaxProgram1.Run; ShowMessage(IntToStr(MyPoint.Y)); end else for I:=0 to PaxCompiler1.ErrorCount do ShowMessage(PaxCompiler1.ErrorMessage[I]); end;
Assigns entry point to a program. Allows to call a script-defined function.procedure SetEntryPoint(EntryPoint: TPaxInvoke);
Example
procedure TTest.Proc(const S: String); begin ShowMessage(S); end; procedure TForm1.Button1Click(Sender: TObject); procedure Print(const S: String); begin ShowMessage(S); end; var H_MyFunc: Integer; I: Integer; P: Pointer; begin {$O-} PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); PaxCompiler1.RegisterHeader(0, 'procedure Print(const S: String);', @Print); PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName); PaxCompiler1.AddCode('1', 'uses SysUtils;'); PaxCompiler1.AddCode('1', 'function MyFunc(U, V: Integer): Currency; cdecl;'); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', ' try'); PaxCompiler1.AddCode('1', ' result := U / V;'); PaxCompiler1.AddCode('1', ' except'); PaxCompiler1.AddCode('1', ' on E: Exception do'); PaxCompiler1.AddCode('1', ' begin'); PaxCompiler1.AddCode('1', ' print(E.Message);'); PaxCompiler1.AddCode('1', ' result := 7;'); PaxCompiler1.AddCode('1', ' end;'); PaxCompiler1.AddCode('1', ' end;'); PaxCompiler1.AddCode('1', 'end;'); PaxCompiler1.AddCode('1', 'begin'); PaxCompiler1.AddCode('1', 'end.'); if PaxCompiler1.Compile(PaxProgram1) then begin H_MyFunc := PaxCompiler1.GetHandle(0, 'MyFunc', true); P := PaxProgram1.GetAddress(H_MyFunc); // get address of script-defined function PaxInvoke1.Address := P; PaxInvoke1.This := nil; // this is not a method, but global function. PaxInvoke1.ClearArguments; PaxInvoke1.AddArgAsInteger(8); PaxInvoke1.AddArgAsInteger(2); PaxInvoke1.SetResultAsCurrency; PaxInvoke1.CallConv := _ccCDECL; PaxProgram1.SetEntryPoint(PaxInvoke1); PaxProgram1.Run; ShowMessage(CurrToStr(Currency(PaxInvoke1.GetResultPtr^))); end else for I:=0 to PaxCompiler1.ErrorCount do ShowMessage(PaxCompiler1.ErrorMessage[I]); end;
Creates instace of script-defined class at run-time.function CreateScriptObject(const ScriptClassName: String): TObject;Arguments
ScriptClassNameName of a script-defined class.
Destroys object of a script-defined class at run-time.procedure DestroyScriptObject(X: TObject);
Forces OnMapTableNamespace, OnMapTableVarAddress, OnMapTableProcAddress, OnMapTableClassRef events for all members registered with global registration routines.procedure MapGlobal;The events allows you to assign addresses and class references of imported host members. See ..\Demos\DemoLoadNamespace in a trial package for Delphi.
Forces OnMapTableNamespace, OnMapTableVarAddress, OnMapTableProcAddress, OnMapTableClassRef events for all members registered with TPaxCompiler registration methods.procedure MapLocal;The events allows you to assign addresses and class references of imported host members. See ..\Demos\DemoLoadNamespace in a trial package for Delphi.
Registeres a namespace.function RegisterNamespace(LevelId: Integer; const Name: String): Integer;This method is used together with RegisterClassType and RegisterAddress and allows you to assign addresses of host-defined members and class references of hos-defined classes to compiled script.
Registeres class type for compiled script.function RegisterClassType(LevelId: Integer; C: TClass): Integer;
Registeres address of host-defined member for compiled script.procedure RegisterMember(LevelId: Integer; const Name: String; Address: Pointer);