TPaxCompiler Events


TPaxCompiler.OnCompilerProgress

Occurs at compile-time.
property OnCompilerProgress: TOnCompilerProgress;

where

TPaxCompilerNotifyEvent = procedure (Sender: TPaxCompiler) of object;
TOnCompilerProgress = TPaxCompilerNotifyEvent;

Example

procedure TForm1.PaxCompiler1CompilerProgress(Sender: TPaxCompiler);
begin
  Application.ProcessMessages;
end;

TPaxCompiler.OnUsedUnit

Occurs when compiler processes the uses clause, it allows you to assign source code of unit at compile-time.
property OnUsedUnit: TPaxCompilerUsedUnitEvent

type
  TPaxCompilerUsedUnitEvent = function (Sender: TPaxCompiler; const UnitName: String; var SourceCode: String): Boolean of object;

Example

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    PaxCompiler1: TPaxCompiler;
    PaxPascalLanguage1: TPaxPascalLanguage;
    PaxProgram1: TPaxProgram;
    procedure Button1Click(Sender: TObject);
    function PaxCompiler1UsedUnit(Sender: TPaxCompiler;
      const UnitName: String; var SourceCode: String): Boolean;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  PaxCompiler1.Reset;
  PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
  PaxCompiler1.AddModule('main', 'Pascal');
  PaxCompiler1.AddCode('main', 'uses SomeUnit;');
  PaxCompiler1.AddCode('main', 'begin');
  PaxCompiler1.AddCode('main', '  P;');
  PaxCompiler1.AddCode('main', 'end.');
  if PaxCompiler1.Compile(PaxProgram1) then
  begin
    PaxProgram1.Run;
  end
  else
    ShowMessage(PaxCompiler1.ErrorMessage[0]);
end;

function TForm1.PaxCompiler1UsedUnit(Sender: TPaxCompiler;
  const UnitName: String; var SourceCode: String): Boolean;
begin
  if UnitName = 'SomeUnit' then
  begin
    result := true;
    SourceCode :=

    'unit SomeUnit;' + #13#10 +
    'interface' + #13#10 +
    'procedure P;' + #13#10 +
    'implementation' + #13#10 +
    'procedure P;' + #13#10 +
    'begin' + #13#10 +
    '  ShowMessage(''Hello'');' + #13#10 +
    'end;' + #13#10 +
    'end.' + #13#10;

  end
  else
    result := false; // default processing
end;

initialization
  RegisterHeader(0, 'procedure ShowMessage(const Msg: string);', @ShowMessage);
end.

TPaxCompiler.OnSavePCU

Occurs when paxCompiler saves compiled unit.
property OnSavePCU: TPaxCompilerSavePCUEvent;

TPaxCompilerSavePCUEvent = function (Sender: TPaxCompiler; const UnitName: String
                              ): TStream of object;

By default, paxCompiler saves compiled units on disk. Use this event to redirect saving pcu to a stream to avoid disk operations.

TPaxCompiler.OnLoadPCU

Occurs when paxCompiler tries to load pcu-file.
property OnLoadPCU: TPaxCompilerLoadPCUEvent;

TPaxCompilerLoadPCUEvent = function (Sender: TPaxCompiler; const UnitName: String
                              ): TStream of object;

By default, paxCompiler loads pcu-files from disk. Use this event to load pcu from a stream.

TPaxCompiler.OnInclude

Occurs when paxCompiler tries to load an included file.
property OnInclude: TPaxCompilerIncludeEvent;

TPaxCompilerIncludeEvent = procedure (Sender: TObject; const FileName: String;
                                var Text: String) of object;

By default, paxCompiler loads included files from disk. Use this event to assign content of included file.

TPaxCompiler.OnDefineDirective

Occurs when paxCompiler processes a define directive.
property OnDefineDirective: TPaxCompilerDirectiveEvent;

TPaxCompilerDirectiveEvent = procedure (Sender: TPaxCompiler;
                          const Directive: String; var ok: Boolean) of object;

TPaxCompiler.OnUndefineDirective

Occurs when paxCompiler processes an undefine directive.
property OnUndefineDirective: TPaxCompilerDirectiveEvent;

TPaxCompilerDirectiveEvent = procedure (Sender: TPaxCompiler;
                          const Directive: String; var ok: Boolean) of object;

TPaxCompiler.OnUnknownDirective

Occurs when paxCompiler processes an unknown directive.
property OnUnknownDirective: TPaxCompilerDirectiveEvent;