Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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