?
Solved

Array of Components?

Posted on 2000-04-21
1
Medium Priority
?
149 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 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

801 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