unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
buttons:
array[0..20]
of TButton;
forms:
array[0..20]
of TForm;
procedure MyBtnClick(Sender: TObject);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
for i:=0
to 5
do
begin
forms[i]:=TForm.Create(self);
forms[i].Visible := true;
forms[i].left:= 40*i;
forms[i].width:= 38;
buttons[i]:=TButton.create(form1);
buttons[i].Left := 20;
buttons[i].top := 80;
buttons[i].height := 35;
buttons[i].width := 80;
buttons[i].Parent := forms[i];
buttons[i].OnClick := MyBtnClick;
buttons[i].Tag := i;
buttons[i].Caption := '
Button ' + IntToStr(i);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var i : byte;
begin
for i:=0
to 5
do
begin
buttons[i].Free;
forms[i].Free;
end;
end;
procedure TForm1.MyBtnClick(Sender: TObject);
begin
showmessage('
du hast geklicked ' + TButton(Sender).Caption);
end;