Solved

control array

Posted on 1998-07-17
7
175 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 74
URL for downloading Google Chrome for Win XP 2 154
Delphi inherited method 6 68
Tvertscrollbox like a whatsapp layout 5 27
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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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