uses Classes; type TMyForm = class(TForm) private Button1: TButton; public constructor Create(AOwner: TComponent); procedure Button1Click(Sender: TObject); end; constructor TMyForm.Create(AOwner: TComponent); begin inherited; Top := 100; Left := 200; Caption := 'Script-defined form MyForm'; Button1 := TButton.Create(Self); Button1.Parent := Self; Button1.Top := 50; Button1.Left := 50; Button1.Caption := 'Click me'; Button1.OnClick := Button1Click; end; procedure TMyForm.Button1Click(Sender: TObject); begin ShowMessage('Hello!'); ShowMessage('Sender: ' + Sender.ClassName); end; var F: TMyForm; begin F := TMyForm.Create(Self); F.Show; end.
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; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure PaxProgram1UnhandledException(Sender: TPaxProgram; E: Exception; const ModuleName: String; SourceLineNumber: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses IMPORT_Classes; var H_TForm: Integer; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin PaxCompiler1.Reset; PaxCompiler1.RegisterLanguage(PaxPascalLanguage1); PaxCompiler1.AddModule('1', 'Pascal'); PaxCompiler1.AddCode('1', Memo1.Lines.Text); PaxCompiler1.RegisterVariable(0, 'Self', H_TForm, @Form1); PaxPascalLanguage1.SetCallConv(_ccREGISTER); if PaxCompiler1.Compile(PaxProgram1) then begin PaxProgram1.Run; end else for I:=0 to PaxCompiler1.ErrorCount - 1 do ShowMessage(PaxCompiler1.ErrorMessage[I]); end; procedure TForm1.PaxProgram1UnhandledException(Sender: TPaxProgram; E: Exception; const ModuleName: String; SourceLineNumber: Integer); begin ShowMessage( 'Exception (' + E.Message + ') raised at line ' + IntToStr(SourceLineNumber) + ':' + PaxCompiler1.Modules[ModuleName][SourceLineNumber] ); end; function TControl_GetParent(Self: TControl): TWinControl; begin result := Self.Parent; end; procedure TControl_SetParent(Self: TControl; Value: TWinControl); begin Self.Parent := Value; end; var H: Integer; initialization H := RegisterClassType(0, TControl); RegisterClassType(0, TWinControl); RegisterHeader(H, 'function _GetParent: TWinControl;', @TControl_GetParent); RegisterHeader(H, 'procedure _SetParent(Value: TWinControl);', @TControl_SetParent); RegisterProperty(H, 'property Parent: TWinControl read _GetParent write _SetParent;'); H_TForm := RegisterClassType(0, TForm); RegisterHeader(H_TForm, 'constructor Create(AOwner: TComponent); override;', @TForm.Create); RegisterHeader(H_TForm, 'procedure Show;', @TForm.Show); H := RegisterClassType(0, TButton); RegisterHeader(H, 'constructor Create(AOwner: TComponent); override;', @TButton.Create); RegisterHeader(0, 'procedure ShowMessage(const Msg: string);', @ShowMessage); end.