首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Pascal脚本中创建带有按钮的窗体?

如何在Pascal脚本中创建带有按钮的窗体?
EN

Stack Overflow用户
提问于 2022-01-30 13:03:43
回答 1查看 286关注 0票数 0

我开始使用PascalScript,但找不到用PascalScript按钮创建表单的方法。

我可以在Lazarus (2.2.0版)中这样做:

代码语言:javascript
复制
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中的“PascalScript”,但是如何将用PascalScript编写的事件分配给此表单上的按钮?

EN

回答 1

Stack Overflow用户

发布于 2022-04-13 01:19:18

我想这就是你要找的

在这里输入图像描述

单元1

代码语言:javascript
复制
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.

第2单元

代码语言:javascript
复制
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.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70914881

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档