?
Solved

Array of Components?

Posted on 2000-04-21
1
Medium Priority
?
151 Views
Last Modified: 2010-04-04
I have a project with a long list of radio buttons.  I dont want to use a dropdown list.  

Is it possible to create an array of radiobuttons (or any other components)? ex.  Radiobutton[x] instead of Radiobutton1, 2 etc.

The end goal is to be able to process their states in a loop rather than each one individually.
0
Comment
Question by:d32coder
1 Comment
 

Accepted Solution

by:
PascalCP earned 200 total points
ID: 2738293
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  LST : TList;               // Contains all the radiobuttons
  I   : integer;             // Counter to autonumber the radiobutton
implementation

{$R *.DFM}

// When button 1 is clicked , there is a radiobutton added to the list
procedure TForm1.Button1Click(Sender: TObject);
var
 rb : TRadiobutton;
begin
  rb := TRadioButton.Create(Self);
  rb.Caption := 'RadioButton ' + inttostr(i);
  Lst.Add(rb);
  i := i + 1;
end;

// when creating the form , we create a list to store our radiobuttons
procedure TForm1.FormCreate(Sender: TObject);
begin
LST := TList.Create;
i := 1;
end;

// when closing the application we free the list of radiobuttons
procedure TForm1.FormDestroy(Sender: TObject);
begin
  LST.Destroy;
end;

// when button 2 is clicked , you see al the radiobuttons in the list
procedure TForm1.Button2Click(Sender: TObject);
var
  idx : integer;
begin
  For idx := 1 to LST.Count do begin
    showmessage(TRadioButton(LST.Items[pred(idx)]).caption);
  end;
end;

end.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question