Solved

Array of Components?

Posted on 2000-04-21
1
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
PascalCP earned 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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