TPaxScripter Demo. Importing Delphi forms.


Lets's create a Delphi application which contains 2 forms:

Form1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, PaxScripter, PaxPascal, StdCtrls;

type
  TForm1 = class(TForm)
    PaxScripter1: TPaxScripter;
    PaxPascal1: TPaxPascal;
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  IMP_Classes, IMP_Controls, IMP_StdCtrls, IMP_Graphics, IMP_Forms;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  PaxScripter1.ResetScripter;
  PaxScripter1.AddModule('1', 'paxPascal');
  PaxScripter1.AddCode('1', 'uses Unit2;');
  PaxScripter1.AddCode('1', 'Form2 := TForm2.Create(nil);');
  PaxScripter1.AddCode('1', 'Form2.ShowModal();');
  PaxScripter1.Run();

  Memo1.Lines.Text := PaxScripter1.SourceCode['Unit2']; // show generated script
end;

end.

Form2 (will be converted in a script module):

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add('Hello!');
end;

end.

Generated script (will be included into the script project at the scripter compile-time):

unit Unit2;
interface
uses
  Classes,
  Graphics,
  Controls,
  Forms,
  StdCtrls;
type
  TForm2 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    constructor Create(AOwner: TComponent);
    procedure Button1Click(Sender: TObject);
  end;

var
  Form2: TForm2;
implementation

constructor TForm2.Create(AOwner: TComponent);
begin
  inherited;
  Button1 := TButton.Create(Self);
  Button1.Name := 'Button1';
  Button1.Parent := Self;
  Button1.Caption := '';
  with Button1 do
  begin
    Left := 24;
    Top := 224;
    Width := 75;
    Height := 25;
    Caption := 'Say "Hello"';
    TabOrder := 0;
    OnClick := Button1Click;
  end;
  Memo1 := TMemo.Create(Self);
  Memo1.Name := 'Memo1';
  Memo1.Parent := Self;
  Memo1.Lines.Text := '';
  with Memo1 do
  begin
    Left := 8;
    Top := 8;
    Width := 465;
    Height := 201;
    TabOrder := 1;
  end;
  Left := 197;
  Top := 191;
  Width := 521;
  Height := 296;
  Caption := 'Form2';
  Color := clBtnFace;
  Font.Charset := DEFAULT_CHARSET;
  Font.Color := clWindowText;
  Font.Height := -11;
  Font.Name := 'MS Sans Serif';
  Font.Style := [];
  OldCreateOrder := False;
  PixelsPerInch := 96;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add('Hello!');
end;
end.


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.