paxCompiler/help/tpaxcompiler_events.htm
Dalibor Marković 9d0de424e8
Init
Signed-off-by: Dalibor Marković <dalibor31@gmail.com>
2024-07-06 22:28:12 +02:00

207 lines
9.3 KiB
HTML

<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H3>
TPaxCompiler Events
</H3>
<hr>
<ul>
<li><a href="#TPaxCompiler.OnCompilerProgress">OnCompilerProgress</a></li>
<li><a href="#TPaxCompiler.OnUsedUnit">OnUsedUnit</a></li>
<li><a href="#TPaxCompiler.OnSavePCU">OnSavePCU</a></li>
<li><a href="#TPaxCompiler.OnLoadPCU">OnLoadPCU</a></li>
<li><a href="#TPaxCompiler.OnInclude">OnInclude</a></li>
<li><a href="#TPaxCompiler.OnDefineDirective">OnDefineDirective</a></li>
<li><a href="#TPaxCompiler.OnUndefineDirective">OnUndefineDirective</a></li>
<li><a href="#TPaxCompiler.OnUnknownDirective">OnUnknownDirective</a></li>
</ul>
<a name="TPaxCompiler.OnCompilerProgress"><h3>TPaxCompiler.OnCompilerProgress</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs at compile-time.
<pre>
<font color="blue"><b>property</b></font> OnCompilerProgress: TOnCompilerProgress;
where
TPaxCompilerNotifyEvent = <font color="blue"><b>procedure</b></font> (Sender: TPaxCompiler) <font color="blue"><b>of</b></font> object;
TOnCompilerProgress = TPaxCompilerNotifyEvent;
</pre>
<p>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>procedure</b></font> TForm1.PaxCompiler1CompilerProgress(Sender: TPaxCompiler);
<font color="blue"><b>begin</b></font>
Application.ProcessMessages;
<font color="blue"><b>end</b></font>;
</pre>
</p>
</blockquote>
<a name="TPaxCompiler.OnUsedUnit"><h3>TPaxCompiler.OnUsedUnit</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when compiler processes the uses clause, it allows you to assign source code of unit at compile-time.
<pre>
<font color="blue"><b>property</b></font> OnUsedUnit: TPaxCompilerUsedUnitEvent
<font color="blue"><b>type</b></font>
TPaxCompilerUsedUnitEvent = <font color="blue"><b>function</b></font> (Sender: TPaxCompiler; <font color="blue"><b>const</b></font> UnitName: <font color="blue"><b>String</b></font>; <font color="blue"><b>var</b></font> SourceCode: <font color="blue"><b>String</b></font>): Boolean <font color="blue"><b>of</b></font> object;
</pre>
<p>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>unit</b></font> Unit1;
<font color="blue"><b>interface</b></font>
<font color="blue"><b>uses</b></font>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, PaxProgram, PaxCompiler, StdCtrls;
<font color="blue"><b>type</b></font>
TForm1 = <font color="blue"><b>class</b></font>(TForm)
Button1: TButton;
PaxCompiler1: TPaxCompiler;
PaxPascalLanguage1: TPaxPascalLanguage;
PaxProgram1: TPaxProgram;
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
<font color="blue"><b>function</b></font> PaxCompiler1UsedUnit(Sender: TPaxCompiler;
<font color="blue"><b>const</b></font> UnitName: <font color="blue"><b>String</b></font>; <font color="blue"><b>var</b></font> SourceCode: <font color="blue"><b>String</b></font>): Boolean;
<font color="blue"><b>private</b></font>
{ Private declarations }
<font color="blue"><b>public</b></font>
{ Public declarations }
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
Form1: TForm1;
<font color="blue"><b>implementation</b></font>
{$R *.dfm}
<font color="blue"><b>procedure</b></font> TForm1.Button1Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
PaxCompiler1.Reset;
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
PaxCompiler1.AddModule(<font color="Red">'main'</font>, <font color="Red">'Pascal'</font>);
PaxCompiler1.AddCode(<font color="Red">'main'</font>, <font color="Red">'uses SomeUnit;'</font>);
PaxCompiler1.AddCode(<font color="Red">'main'</font>, <font color="Red">'begin'</font>);
PaxCompiler1.AddCode(<font color="Red">'main'</font>, <font color="Red">' P;'</font>);
PaxCompiler1.AddCode(<font color="Red">'main'</font>, <font color="Red">'end.'</font>);
<font color="blue"><b>if</b></font> PaxCompiler1.Compile(PaxProgram1) <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
PaxProgram1.Run;
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font>
ShowMessage(PaxCompiler1.ErrorMessage[0]);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>function</b></font> TForm1.PaxCompiler1UsedUnit(Sender: TPaxCompiler;
<font color="blue"><b>const</b></font> UnitName: <font color="blue"><b>String</b></font>; <font color="blue"><b>var</b></font> SourceCode: <font color="blue"><b>String</b></font>): Boolean;
<font color="blue"><b>begin</b></font>
<font color="blue"><b>if</b></font> UnitName = <font color="Red">'SomeUnit'</font> <font color="blue"><b>then</b></font>
<font color="blue"><b>begin</b></font>
result := true;
SourceCode :=
<font color="Red">'unit SomeUnit;'</font> + #13#10 +
<font color="Red">'interface'</font> + #13#10 +
<font color="Red">'procedure P;'</font> + #13#10 +
<font color="Red">'implementation'</font> + #13#10 +
<font color="Red">'procedure P;'</font> + #13#10 +
<font color="Red">'begin'</font> + #13#10 +
<font color="Red">' ShowMessage('</font><font color="Red">'Hello'</font><font color="Red">');'</font> + #13#10 +
<font color="Red">'end;'</font> + #13#10 +
<font color="Red">'end.'</font> + #13#10;
<font color="blue"><b>end</b></font>
<font color="blue"><b>else</b></font>
result := false; // default processing
<font color="blue"><b>end</b></font>;
<font color="blue"><b>initialization</b></font>
RegisterHeader(0, <font color="Red">'procedure ShowMessage(const Msg: string);'</font>, @ShowMessage);
<font color="blue"><b>end</b></font>.
</pre>
</p>
</blockquote>
<a name="TPaxCompiler.OnSavePCU"><h3>TPaxCompiler.OnSavePCU</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler saves compiled unit.
<pre>
<font color="blue"><b>property</b></font> OnSavePCU: TPaxCompilerSavePCUEvent;
TPaxCompilerSavePCUEvent = <font color="blue"><b>function</b></font> (Sender: TPaxCompiler; <font color="blue"><b>const</b></font> UnitName: <font color="blue"><b>String</b></font>
): TStream <font color="blue"><b>of</b></font> object;
</pre>
<p>
By default, paxCompiler saves compiled units on disk. Use this event to redirect saving pcu to a stream to avoid disk operations.
</p>
</blockquote>
<a name="TPaxCompiler.OnLoadPCU"><h3>TPaxCompiler.OnLoadPCU</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler tries to load pcu-file.
<pre>
<font color="blue"><b>property</b></font> OnLoadPCU: TPaxCompilerLoadPCUEvent;
TPaxCompilerLoadPCUEvent = <font color="blue"><b>function</b></font> (Sender: TPaxCompiler; <font color="blue"><b>const</b></font> UnitName: <font color="blue"><b>String</b></font>
): TStream <font color="blue"><b>of</b></font> object;
</pre>
<p>
By default, paxCompiler loads pcu-files from disk. Use this event to load pcu from a stream.
</p>
</blockquote>
<a name="TPaxCompiler.OnInclude"><h3>TPaxCompiler.OnInclude</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler tries to load an included file.
<pre>
<font color="blue"><b>property</b></font> OnInclude: TPaxCompilerIncludeEvent;
TPaxCompilerIncludeEvent = <font color="blue"><b>procedure</b></font> (Sender: TObject; <font color="blue"><b>const</b></font> FileName: <font color="blue"><b>String</b></font>;
<font color="blue"><b>var</b></font> Text: <font color="blue"><b>String</b></font>) <font color="blue"><b>of</b></font> object;
</pre>
<p>
By default, paxCompiler loads included files from disk. Use this event to assign content of included file.
</p>
</blockquote>
<a name="TPaxCompiler.OnDefineDirective"><h3>TPaxCompiler.OnDefineDirective</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler processes a define directive.
<pre>
<font color="blue"><b>property</b></font> OnDefineDirective: TPaxCompilerDirectiveEvent;
TPaxCompilerDirectiveEvent = <font color="blue"><b>procedure</b></font> (Sender: TPaxCompiler;
<font color="blue"><b>const</b></font> Directive: <font color="blue"><b>String</b></font>; <font color="blue"><b>var</b></font> ok: Boolean) <font color="blue"><b>of</b></font> object;
</pre>
</blockquote>
<a name="TPaxCompiler.OnUndefineDirective"><h3>TPaxCompiler.OnUndefineDirective</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler processes an undefine directive.
<pre>
<font color="blue"><b>property</b></font> OnUndefineDirective: TPaxCompilerDirectiveEvent;
TPaxCompilerDirectiveEvent = <font color="blue"><b>procedure</b></font> (Sender: TPaxCompiler;
<font color="blue"><b>const</b></font> Directive: <font color="blue"><b>String</b></font>; <font color="blue"><b>var</b></font> ok: Boolean) <font color="blue"><b>of</b></font> object;
</pre>
</blockquote>
<a name="TPaxCompiler.OnUnknownDirective"><h3>TPaxCompiler.OnUnknownDirective</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Occurs when paxCompiler processes an unknown directive.
<pre>
<font color="blue"><b>property</b></font> OnUnknownDirective: TPaxCompilerDirectiveEvent;
</pre>
</blockquote>
</body>