unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    PaxCompiler1: TPaxCompiler;
    PaxPascalLanguage1: TPaxPascalLanguage;
    PaxProgram1: TPaxProgram;
    procedure PaxProgram1UnhandledException(Sender: TPaxProgram; E: Exception;
      const ModuleName: String; SourceLineNumber: Integer);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses IMPORT_SysUtils;

{$R *.dfm}

procedure TForm1.PaxProgram1UnhandledException(Sender: TPaxProgram;
  E: Exception; const ModuleName: String; SourceLineNumber: Integer);
begin
  ShowMessage('Run-time error (' + E.Message + ') raised at line ' + IntToStr(SourceLineNumber) + ':' +
      PaxCompiler1.Modules[ModuleName][SourceLineNumber]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PaxCompiler1.Reset;
  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
  PaxCompiler1.AddModule('main', 'Pascal');
  PaxCompiler1.AddCode('main', 'uses SysUtils;');
  PaxCompiler1.AddCode('main', 'begin');
  PaxCompiler1.AddCode('main', '  raise Exception.Create(''Error'');');
  PaxCompiler1.AddCode('main', 'end.');
  if PaxCompiler1.Compile(PaxProgram1) then
  begin
    PaxProgram1.Run;
  end
  else
    ShowMessage('Compile error: ' + PaxCompiler1.ErrorMessage[0] + ' at line ' + #13#10 +
                PaxCompiler1.ErrorLine[0]);
end;

end.
