?
Solved

control array

Posted on 1998-07-17
7
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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

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.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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