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.