unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PaxCompiler, PaxProgram, PaxRegister;

type
  TForm1 = class(TForm)
    PaxCompiler1: TPaxCompiler;
    PaxPascalLanguage1: TPaxPascalLanguage;
    PaxProgram1: TPaxProgram;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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, @MyPoint);

  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.Run;
    ShowMessage(IntToStr(MyPoint.Y));
  end
  else
    for I:=0 to PaxCompiler1.ErrorCount do
      ShowMessage(PaxCompiler1.ErrorMessage[I]);
end;

end.
