Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

any way to enumerate component names? 2

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB
Hi,

In my app I have a whole bunch of comboboxes.
When the user has put some text in all of these I want to run some validation on the combobox text, and depending on the results, process it.
In each case the same validation procedure could be used.

If I had
ComboBox0
ComboBox1
ComboBox2
ComboBox3
to
ComboBox25

what I would like to do is something like
Code:
for count = 0 to 25 do
begin
   validate(ComboBox[count].text);  [COLOR=green]//where validate() is my validation procedure that needs the text of each combobox passing to it[/color]
   If result then Strings[count] := ComboxBox[count].Text
end;

Is this possible in any way?



Steve (Delphi 2007 & XP)
 
Yes. With TComponent.

This throws a string up on every TMemo in the form.

Code:
procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
  Temp: TComponent;
  TempMemo: TMemo;
begin
  for i := 0 to Form1.ComponentCount-1 do
    begin
      Temp := Form1.Components[i];
      if (Temp is TMemo) then
        begin
          TempMemo := TMemo(Temp);
          TempMemo.Lines.Add(Temp.name + ' is added.');
        end;
    end;
end;
 
you can also put them into an array.

Code:
MyCombos: array [0..3] of TComboBox;

form create
Code:
MyCombos[0] := ComboBox1;
MyCombos[1] := ComboBox2;
MyCombos[2] := ComboBox3;
MyCombos[3] := ComboBox4;

Code:
for i := 0 to 3 do MyCombos[i].property := yada;


Aaron
 
Thanks guys, both of those methods are extremely useful!


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top