• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

control array

Hello.

I want to use control array like Visual Basic.
Can I program component as array?
Please teach me how to program and a example.

 
0
sakya
Asked:
sakya
1 Solution
 
pjdbCommented:
For example, an array of 3 edit boxes (alreadyt defined on the form)

in the private part of the form put : MyControlArray=Array[0..2] Of TEdit;
in the OnCreate event of the form put :
MyControlArray[0]:=Edit1;
MyControlArray[1]:=Edit2;
MyControlArray[2]:=Edit3;

Then you can use them whereever you want by either using Edit1, Edit2, Edit3 or MyControlArray[i].
0
 
sakyaAuthor Commented:
Yes,but I know this way.
I want more cool code because my application has hundreds of components,

Help.


0
 
vladikaCommented:
Any component has property Components and ComponentCount.
Components lists of all components owned by the component.

Any wincontrol has property Controls and ControlCount.
The Controls property is an array of all controls that are children of the windowed control.

Try to use it.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ZifNabCommented:
you could also use a TList to contain your components...
0
 
sakyaAuthor Commented:
Thanks vladika.
Thanks ZifNab.

I will try.



0
 
viktornetCommented:
Try this:
var i:integer;
for i := 0 to ComponentCount - 1 do
  begin
    if (Components[i] is TButton) then
     with (Components[i] as TButton) do
       begin
         //your code goes here
       end;
  end;
//another example
procedure TMainForm.Button1click(Sender: TObject);
 var
   i: integer;
 begin
   for i:=0 TO MainForm.ComponentCount-1 do
   begin
     (if Components[i] is TEdit) then
       TEdit(Components[i]).Text := IntToStr(TEdit(Components[i]).Tag);
    end;
 end;

If there is something specific that you don't understand you can E-mail me at viktor@megsinet.net...I'll try to do my best.. C'ya

Viktor Ivanov
0
 
sakyaAuthor Commented:
viktornet. Thanks for  your good  examples.

 
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now