Solved

Array of Components?

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Downloading email attachments 2 80
can't find the executable in Simulator 1 101
Delphi: Connect to running MS Outlook 4 123
Tvertscrollbox like a whatsapp layout 5 36
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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