...create an Array of TButtons at runtime?
Author: Thomas Stutz
private
{...}
procedure RunTimeButtonClick(Sender: TObject);
end;
{...}
var
Form1: TForm;
{Declare an Array of TButtons}
RunTimeButtons: array[1..10] of TButton;
{...}
implementation
{...}
procedure TForm1.RunTimeButtonClick(Sender: TObject);
begin
{Show the Button Nummer that was clicked}
ShowMessage('Button' + IntToStr((Sender as TButton).Tag) + ' clicked!');
end;
procedure TForm1.Button13Click(Sender: TObject);
var
i: Byte;
begin
for i := 1 to 10 do
begin
{Create the buttons}
RunTimeButtons[i] := TButton.Create(Self);
with RunTimeButtons[i] do
begin
Parent := Form1;
Caption := 'Button ' + IntToStr(i);
Top := i * Height;
Tag := i;
{Assign a OnClick handler}
OnClick := RunTimeButtonClick;
Visible := True;
end;
end;
end;
printed from
www.swissdelphicenter.ch
developers knowledge base