Hi,
vieleicht möchte ja jemand mehrere Buttons erstellen
...
Delphi-Quellcode:
procedure DynamicClickProcedure(Self: TButton; Sender: TObject);
begin
if Assigned( Sender ) and (Sender is TButton) then
with TButton( Sender ) do
begin
ShowMessage( Format( '%d. Button wurde gedrückt', [Tag] ));
case Tag of
1: ;
2: ;
3: ;
4: ;
5: ;
6: ;
7: ;
8: ;
9: ;
10: ;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
const
cbHeight = 30;
cbSpace = 5;
var
NewButton: TButton;
i : Longint;
begin
for i := 1 to 10 do
begin
NewButton := TButton.Create(Self);
with NewButton do
begin
Parent := Self;
Caption := 'Neuer Button';
Top := 10 + ((i-1) * cbHeight ) + ((i-1) * cbSpace);
Left := 10;
Height := cbHeight;
Width := 100;
Tag := i;
@OnClick := @DynamicClickProcedure;
end;
end;
end;
mfg Rumpi