Solved

control array

Posted on 1998-07-17
7
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
you could also use a TList to contain your components...
0
 

Author Comment

by:sakya
Comment Utility
Thanks vladika.
Thanks ZifNab.

I will try.



0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
Comment Utility
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
Comment Utility
viktornet. Thanks for  your good  examples.

 
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now