unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I, t: Integer;
begin
  PaxCompiler1.Reset;
  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);

  PaxCompiler1.AddModule('1', 'Pascal');
  PaxCompiler1.AddCode('1', Memo1.Lines.Text);
  if PaxCompiler1.Compile(PaxProgram1) then
  begin
    t := GetTickCount();
    PaxProgram1.Run;
    t := GetTickCount() - t;
    ShowMessage(IntToStr(t));
  end
  else
    for I:=0 to PaxCompiler1.ErrorCount - 1 do
      ShowMessage(PaxCompiler1.ErrorMessage[I]);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  t, i, j: Integer;
  c: TComponent;
begin
  t := GetTickCount();
  c := TComponent.Create(nil);
  for i := 0 to 500000 do
    if c.Tag = 0 then
    begin
      c.Tag := 0;
      c.Name := 'a';
    end;
  c.Free;
  t := GetTickCount() - t;
  ShowMessage(IntToStr(t));
end;

var
  H: Integer;
initialization
  H := RegisterClassType(0, TComponent);
  RegisterHeader(H, 'constructor Create(AOwner: TComponent); virtual;', @TComponent.Create);
end.
