unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure test(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.test(Sender: TObject);
var
l_busin_flag:Integer;
begin
l_busin_flag:=(Sender as TButton).Tag;
ShowMessage(IntToStr(l_busin_flag)+'Hello');
end;
procedure TForm1.FormCreate(Sender: TObject);
var
btns: TButton;
i:Integer;
begin
for i:=0 to 5 do
begin
btns:=TButton.Create(Self);
btns.Width:=100;
btns.Height:=20;
btns.Caption:=IntToStr(i)+'动态按钮';
btns.OnClick:=test;
btns.Left:=i*100;
btns.Tag:=i;
btns.Parent:=Self;
end;
end;
end.
Delphi 代码创建控件与事件动态绑定
最新推荐文章于 2023-03-10 17:41:02 发布