whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

13 Visitors Online


 
...create an Array of TButtons at runtime?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (7):  
     


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;



 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners