### TPaxProgram Methods

- Create
- Destroy
- DiscardPause
- GetAddress
- GetImageSize
- IsPaused
- IsRunning
- LoadFromFile
- LoadFromStream
- Pause
- Resume
- Run
- SaveToFile
- SaveToStream
- SetAddress
- SetEntryPoint
- CreateScriptObject
- DestroyScriptObject
- MapGlobal
- MapLocal
- RegisterNamespace
- RegisterClassType
- RegisterMember

### TPaxProgram.Create

> Constructor of TPaxProgram class.

>     constructor Create(AOwner: TComponent); override;

### TPaxProgram.Destroy

> Destructor of TPaxProgram class.

>     destructor Destroy; override;

### TPaxProgram.DiscardPause

> Terminates a paused program.

>     procedure DiscardPause;

### TPaxProgram.GetAddress

> Returns address of a script-defined variable, procedure or function.

>     function GetAddress(Handle: Integer): Pointer;
>     function GetAddress(const FullName: String): Pointer;

> #### Arguments

> > Handle

> > > Id 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;

### TPaxProgram.GetImageSize

> Returns size of image of compiled program.

>     function GetImageSize: Integer;

### TPaxProgram.IsPaused

> Returns 'true', if script is in the paused state.

>     function IsPaused: Boolean;

### TPaxProgram.IsRunning

> Returns 'true', if component runs a program.

>     function IsRunning: Boolean;

### TPaxProgram.LoadFromFile

> 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;

### TPaxProgram.LoadFromStream

> Loads program from a stream.

>     procedure LoadFromStream(S: TStream);

### TPaxProgram.Pause

> Pauses script.

>     procedure Pause;

### TPaxProgram.Resume

> Resumes a paused script.

>     procedure Resume;

### TPaxProgram.Run

> 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;

### TPaxProgram.SaveToFile

> Saves program to a binary file.

>     procedure SaveToFile(const Path: String);

### TPaxProgram.SaveToStream

> Saves program to a stream.

>     procedure SaveToStream(S: TStream);

### TPaxProgram.SetAddress

> Sets address of a host-defined variable, procedure or function.

>     procedure SetAddress(Handle: Integer; P: Pointer);

> #### Arguments

> > Handle

> > > Id of a host-defined variable, procedure or function.

> > P

> > > Address

> #### 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;

### TPaxProgram.SetEntryPoint

> 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;

### TPaxProgram.CreateScriptObject

> Creates instace of script-defined class at run-time.

>     function CreateScriptObject(const ScriptClassName: String): TObject;

> #### Arguments

> > ScriptClassName

> > > Name of a script-defined class.

### TPaxProgram.DestroyScriptObject

> Destroys object of a script-defined class at run-time.

>     procedure DestroyScriptObject(X: TObject);

### TPaxProgram.MapGlobal

> 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.

### TPaxProgram.MapLocal

> 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.

### TPaxProgram.RegisterNamespace

> 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.

### TPaxProgram.RegisterClassType

> Registeres class type for compiled script.

>     function RegisterClassType(LevelId: Integer; C: TClass): Integer;

### TPaxProgram.RegisterMember

> Registeres address of host-defined member for compiled script.

>     procedure RegisterMember(LevelId: Integer; const Name: String; Address: Pointer);