Delphi-Quellcode:
while(z<10) do
begin
if (myButton[z] = nil) then
begin
myButton[z] := TButton.Create(self);
with myButton[z] do
begin
Parent := myScrollBox[n];
Caption:='Button '+inttostr(z) ;
Name:='Button'+inttostr(z);
Height:=22;
Width:=130;
Left := 10;
Top :=23
onClick := Form1.ButtonClick;
end;
end;
inc(z);
end;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(Sender as TComponent).Name);
end;
[Edit: Sniper was schneller, aber es geht aucch über Namen}