unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    PaxProgram1: TPaxProgram;
    PaxCompiler1: TPaxCompiler;
    PaxPascalLanguage1: TPaxPascalLanguage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure TestScript(const FileName: String);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.TestScript(const FileName: String);
var
  I: Integer;
begin
  PaxCompiler1.Reset;
  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
  PaxCompiler1.AddModule('1', PaxPascalLanguage1.LanguageName);
  PaxCompiler1.AddCodeFromFile('1', FileName);

  if PaxCompiler1.Compile(PaxProgram1) then
    PaxProgram1.Run
  else
    for I:=0 to PaxCompiler1.ErrorCount - 1 do
      ShowMessage(PaxCompiler1.ErrorMessage[I]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TestScript('script1.txt');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  TestScript('script2.txt');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  TestScript('script3.txt');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  TestScript('script4.txt');
end;

procedure PrintInt(I: Integer);
begin
  ShowMessage(IntToStr(I));
end;

procedure PrintStr(const S: String);
begin
  ShowMessage(S);
end;

initialization

RegisterHeader(0, 'procedure PrintInt(I: Integer);', @PrintInt);
RegisterHeader(0, 'procedure PrintStr(const S: String);', @PrintStr);

end.
