我开始使用 PascalScript,但找不到从 PascalScript 创建带有按钮的表单的方法。
我可以从 Lazarus(版本 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;
然后使用 PascalScript 中的“CreateForm”,但是我如何将 PascalScript 编写的事件分配给该表单上的按钮?
我想这就是您要找的:
第一单元:
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 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.