Solved

control array

Posted on 1998-07-17
7
177 Views
Last Modified: 2010-04-04
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
Comment
Question by:sakya
7 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1358077
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
 

Author Comment

by:sakya
ID: 1358078
Yes,but I know this way.
I want more cool code because my application has hundreds of components,

Help.


0
 
LVL 3

Expert Comment

by:vladika
ID: 1358079
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
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.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1358080
you could also use a TList to contain your components...
0
 

Author Comment

by:sakya
ID: 1358081
Thanks vladika.
Thanks ZifNab.

I will try.



0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1358082
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
 

Author Comment

by:sakya
ID: 1358083
viktornet. Thanks for  your good  examples.

 
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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