Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Create an array of components - Components - Tips & Tricks - Greatis Delphi Pages

First of all, you need to declare the array.
Then, if you will create the Button components dynamically, you may execute procedure BitBtn1Click.
Then, if you will create the Button components static, you may execute procedure BitBtn2Click.


var
  Edits : array[1..5] of TEdit;
  SPButtons: array[1..5] of TSpeedButton;

implementations

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  i: Integer;
begin
  for i:=1 to 5 do
  begin
    Edits[i]:=TEdit.Create(Form1);
    Edits[i].Parent:= Form1;
    Edits[i].Left:=40;
    Edits[i].Top:=Form1.Height-(5-i)*40-100;
    Edits[i].Text:='Edit '+IntToStr(i);
  end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
  Btns, Counter: Integer;
begin
  Btns:=0;
  for Counter:=0 to Form1.ComponentCount-1 do
  begin
    if (Components[Counter] is TSpeedButton) and (Btns<5) then
    begin
      Inc(Btns);
      SPButtons[Btns]:=TSpeedButton(Components[Counter]);
      SPButtons[Btns].Caption:='SP'+IntToStr(Btns);
    end
  end;
end;
Related chapters
Databases

Related topics
Create component at runtime
Add controls to TabbedNotebook
Create TTable without a form
Duplicate component

For more
Delphi Help

Download source