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

174 lines
6.0 KiB
HTML

<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H2>
paxCompiler for Delphi. Inheritance of host-defined classes.
</H2>
<hr>
<h4>Script</h4>
<blockquote>
<pre>
<font color="blue"><b>uses</b></font>
Classes;
<font color="blue"><b>type</b></font>
TMyForm = <font color="blue"><b>class</b></font>(TForm)
<font color="blue"><b>private</b></font>
Button1: TButton;
<font color="blue"><b>public</b></font>
<font color="blue"><b>constructor</b></font> Create(AOwner: TComponent);
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>constructor</b></font> TMyForm.Create(AOwner: TComponent);
<font color="blue"><b>begin</b></font>
<font color="blue"><b>inherited</b></font>;
Top := 100;
Left := 200;
Caption := <font color="Red">'Script-defined form MyForm'</font>;
Button1 := TButton.Create(Self);
Button1.Parent := Self;
Button1.Top := 50;
Button1.Left := 50;
Button1.Caption := <font color="Red">'Click me'</font>;
Button1.OnClick := Button1Click;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TMyForm.Button1Click(Sender: TObject);
<font color="blue"><b>begin</b></font>
ShowMessage(<font color="Red">'Hello!'</font>);
ShowMessage(<font color="Red">'Sender: '</font> + Sender.ClassName);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
F: TMyForm;
<font color="blue"><b>begin</b></font>
F := TMyForm.Create(Self);
F.Show;
<font color="blue"><b>end</b></font>.
</pre>
</blockquote>
<h4>Delphi Application</h4>
<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, 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;
Memo1: TMemo;
<font color="blue"><b>procedure</b></font> Button1Click(Sender: TObject);
<font color="blue"><b>procedure</b></font> PaxProgram1UnhandledException(Sender: TPaxProgram;
E: Exception; <font color="blue"><b>const</b></font> ModuleName: <font color="blue"><b>String</b></font>; SourceLineNumber: Integer);
<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>uses</b></font>
IMPORT_Classes;
<font color="blue"><b>var</b></font>
H_TForm: Integer;
<font color="blue"><b>procedure</b></font> TForm1.Button1Click(Sender: TObject);
<font color="blue"><b>var</b></font>
I: Integer;
<font color="blue"><b>begin</b></font>
PaxCompiler1.Reset;
PaxCompiler1.RegisterLanguage(PaxPascalLanguage1);
PaxCompiler1.AddModule(<font color="Red">'1'</font>, <font color="Red">'Pascal'</font>);
PaxCompiler1.AddCode(<font color="Red">'1'</font>, Memo1.Lines.Text);
PaxCompiler1.RegisterVariable(0, <font color="Red">'Self'</font>, H_TForm, @Form1);
PaxPascalLanguage1.SetCallConv(_ccREGISTER);
<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>
<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>end</b></font>;
<font color="blue"><b>procedure</b></font> TForm1.PaxProgram1UnhandledException(Sender: TPaxProgram;
E: Exception; <font color="blue"><b>const</b></font> ModuleName: <font color="blue"><b>String</b></font>; SourceLineNumber: Integer);
<font color="blue"><b>begin</b></font>
ShowMessage(
<font color="Red">'Exception ('</font> + E.Message +
<font color="Red">') raised at line '</font> + IntToStr(SourceLineNumber) + <font color="Red">':'</font> +
PaxCompiler1.Modules[ModuleName][SourceLineNumber]
);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>function</b></font> TControl_GetParent(Self: TControl): TWinControl;
<font color="blue"><b>begin</b></font>
result := Self.Parent;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> TControl_SetParent(Self: TControl; Value: TWinControl);
<font color="blue"><b>begin</b></font>
Self.Parent := Value;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
H: Integer;
<font color="blue"><b>initialization</b></font>
H := RegisterClassType(0, TControl);
RegisterClassType(0, TWinControl);
RegisterHeader(H, <font color="Red">'function _GetParent: TWinControl;'</font>, @TControl_GetParent);
RegisterHeader(H, <font color="Red">'procedure _SetParent(Value: TWinControl);'</font>, @TControl_SetParent);
RegisterProperty(H, <font color="Red">'property Parent: TWinControl read _GetParent write _SetParent;'</font>);
H_TForm := RegisterClassType(0, TForm);
RegisterHeader(H_TForm, <font color="Red">'constructor Create(AOwner: TComponent); override;'</font>,
@TForm.Create);
RegisterHeader(H_TForm, <font color="Red">'procedure Show;'</font>, @TForm.Show);
H := RegisterClassType(0, TButton);
RegisterHeader(H, <font color="Red">'constructor Create(AOwner: TComponent); override;'</font>,
@TButton.Create);
RegisterHeader(0, <font color="Red">'procedure ShowMessage(const Msg: string);'</font>, @ShowMessage);
<font color="blue"><b>end</b></font>.
</pre>
</blockquote>
<p>
<HR>
<font size = 1 color ="gray">
Copyright &copy; 2006-2009
VIRT Laboratory. All rights reserved.
</font>
</body>
</html>