124 lines
4.6 KiB
HTML
124 lines
4.6 KiB
HTML
<html>
|
|
<head>
|
|
<link rel=stylesheet type="text/css" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<H2>
|
|
paxCompiler for Delphi. Loading compiled scripts.
|
|
</H2>
|
|
<hr>
|
|
|
|
|
|
<blockquote>
|
|
<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, Classes, Graphics, Controls, Forms,
|
|
Dialogs, StdCtrls, PaxCompiler, PaxProgram;
|
|
<font color="blue"><b>type</b></font>
|
|
TForm1 = <font color="blue"><b>class</b></font>(TForm)
|
|
Button1: TButton;
|
|
Button2: TButton;
|
|
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
|
|
<font color="blue"><b>procedure</b></font> Button2Click(Sender: TObject);
|
|
<font color="blue"><b>procedure</b></font> FormCreate(Sender: TObject);
|
|
<font color="blue"><b>private</b></font>
|
|
H_ShowMessage: Integer;
|
|
H_S: Integer;
|
|
S: AnsiString;
|
|
{ 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>var</b></font>
|
|
I: Integer;
|
|
PaxCompiler1: TPaxCompiler;
|
|
PaxPascalLanguage1: TPaxPascalLanguage;
|
|
PaxProgram1: TPaxProgram;
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxCompiler1 := TPaxCompiler.Create(<font color="blue"><b>nil</b></font>);
|
|
PaxPascalLanguage1 := TPaxPascalLanguage.Create(<font color="blue"><b>nil</b></font>);
|
|
PaxProgram1 := TPaxProgram.Create(<font color="blue"><b>nil</b></font>);
|
|
|
|
<font color="blue"><b>try</b></font>
|
|
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
|
|
|
|
// register routine ShowMessage
|
|
H_ShowMessage := PaxCompiler1.RegisterHeader(0, <font color="Red">'procedure ShowMessage(const Msg: string);'</font>);
|
|
|
|
// register variable S
|
|
H_S := PaxCompiler1.RegisterVariable(0, <font color="Red">'S'</font>, _typeSTRING);
|
|
|
|
PaxCompiler1.AddModule(<font color="Red">'1'</font>, PaxPascalLanguage1.LanguageName);
|
|
PaxCompiler1.AddCode(<font color="Red">'1'</font>, <font color="Red">'begin'</font>);
|
|
PaxCompiler1.AddCode(<font color="Red">'1'</font>, <font color="Red">' ShowMessage(S);'</font>);
|
|
PaxCompiler1.AddCode(<font color="Red">'1'</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.SaveToFile(<font color="Red">'1.bin'</font>);
|
|
ShowMessage(<font color="Red">'Compiled script has been created!'</font>);
|
|
<font color="blue"><b>end</b></font>
|
|
<font color="blue"><b>else</b></font>
|
|
<font color="blue"><b>for</b></font> I:=0 <font color="blue"><b>to</b></font> PaxCompiler1.ErrorCount - 1 <font color="blue"><b>do</b></font>
|
|
ShowMessage(PaxCompiler1.ErrorMessage[I]);
|
|
<font color="blue"><b>finally</b></font>
|
|
PaxCompiler1.Free;
|
|
PaxPascalLanguage1.Free;
|
|
PaxProgram1.Free;
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TForm1.Button2Click(Sender: TObject);
|
|
<font color="blue"><b>var</b></font>
|
|
PaxProgram1: TPaxProgram;
|
|
<font color="blue"><b>begin</b></font>
|
|
<font color="blue"><b>if</b></font> FileExists(<font color="Red">'1.bin'</font>) <font color="blue"><b>and</b></font> (H_ShowMessage <> 0) <font color="blue"><b>and</b></font> (H_S <> 0) <font color="blue"><b>then</b></font>
|
|
<font color="blue"><b>begin</b></font>
|
|
PaxProgram1 := TPaxProgram.Create(<font color="blue"><b>nil</b></font>);
|
|
<font color="blue"><b>try</b></font>
|
|
PaxProgram1.LoadFromFile(<font color="Red">'1.bin'</font>);
|
|
PaxProgram1.SetAddress(H_ShowMessage, @ShowMessage);
|
|
PaxProgram1.SetAddress(H_S, @S);
|
|
PaxProgram1.Run;
|
|
<font color="blue"><b>finally</b></font>
|
|
PaxProgram1.Free;
|
|
<font color="blue"><b>end</b></font>;
|
|
<font color="blue"><b>end</b></font>
|
|
<font color="blue"><b>else</b></font>
|
|
ShowMessage(<font color="Red">'Press the first button to create compiled script.'</font>);
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>procedure</b></font> TForm1.FormCreate(Sender: TObject);
|
|
<font color="blue"><b>begin</b></font>
|
|
H_ShowMessage := 0;
|
|
H_S := 0;
|
|
S := <font color="Red">'Hello'</font>;
|
|
<font color="blue"><b>end</b></font>;
|
|
|
|
<font color="blue"><b>end</b></font>.
|
|
</pre>
|
|
</blockquote>
|
|
|
|
|
|
<p>
|
|
<HR>
|
|
<font size = 1 color ="gray">
|
|
Copyright © 2006-2009
|
|
VIRT Laboratory. All rights reserved.
|
|
</font>
|
|
</body>
|
|
</html>
|