Solved

Array of Components?

Posted on 2000-04-21
1
142 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 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now