求Delphi代码中新增按钮,新建过程和调用过程的代码

来源:百度知道 编辑:UC知道 时间:2024/05/28 17:31:37
求Delphi代码中新增按钮,新建过程和调用过程的代码。
首先,建立一个过程,过程内容为:
Showmessage('新增按钮被调用');
其次,在窗体中新建了一个按钮,其功能为单击该按钮时在窗体上产生一个新按钮,并调用前面建立的过程。
目的是给新增的按钮写OnClick事件。求完整代码,包含接口部分。

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
NewButton :TButton;

implementation

{$R *.dfm}

procedure TForm1.NewButtonClick(Sender: TObject);
begin
Showmessage('新增按钮被调用');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
NewButton := TButton.Create(self);
NewButton.Parent := Form1;
NewButton.Left := 10;
NewButton.Top := 10;
NewButton.Caption := 'New Button';
NewButton.OnCli