TPaxScripter.OnHalt event demo.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, PaxScripter, PaxPascal, BASE_PARSER;

type
  TForm1 = class(TForm)
    Button1: TButton;
    PaxPascal1: TPaxPascal;
    procedure Button1Click(Sender: TObject);
  private
     S: TPaxScripter;
    { Private declarations }
    procedure OnHalt(Sender: TPaxScripter);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses IMP_Forms;

procedure TForm1.Button1Click(Sender: TObject);
begin
  S := TPaxScripter.Create(Self);
  S.RegisterLanguage(PaxPascal1);
  S.AddModule('1', 'paxPascal');
  S.AddCodeFromFile('1', 'script.txt');
  S.OnHalt := OnHalt;
  S.Run();
end;

procedure TForm1.OnHalt(Sender: TPaxScripter);
begin
  S.Free;
  ShowMessage('scripter has been destroyed');
end;

end.

script.txt:

uses
  Forms;
var
  Frm : TForm;
procedure FrmClose(Sender : Tobject; var Action : TCloseAction);
begin
  Action := caFree;
  print 'done';
  Halt;
end;

begin
  Frm := Forms.TForm.Create(nil);
  Frm.OnClose := @FrmClose;
  Frm.Show;
end.


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.