Tom
Tom

Reputation: 3044

How to create a form with a button in Pascal Script?

I started using PascalScript and I can't find a way to create a form with a button from PascalScript.

I can do this from Lazarus (version 2.2.0):

procedure TForm1.PSScript1Compile(Sender: TPSScript);
begin     
  Sender.AddFunction(@CreateForm, 'procedure CreateForm');
end;

procedure CreateForm;
var F1: TForm;
begin
  F1 := TForm.Create(Application);
  F1.ShowModal;
  F1.Free;
end;  

and then use "CreateForm" from PascalScript but then how would I assign events written in PascalScript to buttons on this form?

Upvotes: 0

Views: 1043

Answers (1)

I think this is what you looking for:

Delphi Programming

Unit 1:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  th:btnThread;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
th:=btnThread.create(Form1);

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
th.Free;
end;

end.

end.

Unit 2:

unit Unit2;

interface

uses
  Forms, StdCtrls, Graphics, ExtCtrls, ClipBrd, Contnrs, JPeg, SysUtils,
  ComCtrls,Messages, Windows,classes;

type

  btnThread = class
  private
    { Private declarations }
    FForm: TForm;
    btn:Tbutton;

  protected
  public
    constructor Create(AForm: TForm);
  end;

implementation

{ TProgressBarThread }
constructor btnThread.Create(AForm: TForm);
begin
  FForm := TForm.Create(nil);
  btn := Tbutton.Create(FForm);


  with FForm do
  begin
    Caption := 'Please Wait...';
    Left := 277;
    Top := 296;
    BorderIcons := [biSystemMenu];
    BorderStyle := bsSingle;
    ClientHeight := 80;
    ClientWidth := 476;
    Color := clBtnFace;
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'MS Sans Serif';
    Font.Style := [];
    FormStyle := fsStayOnTop;
    OldCreateOrder := False;
    Position := poMainFormCenter;
    PixelsPerInch := 96;



    with btn do
    begin
      Parent := FForm;
      Left := 16;
      Top := 24;
      Width := 80;
      Height := 33;
      Caption := 'button';

    end;
  FForm.Show;

end;
    end;
end.

Upvotes: 0

Related Questions