Board index » delphi » Form and ControlCount

Form and ControlCount


2003-12-20 01:33:56 AM
delphi24
Hi all,
I have e Form1 with same components...
My routine
function checkControl: Boolean;
var
i: Integer;
MyTest: String;
Begin
For i := 0 to Form1.ControlCount - 1 do
Begin
...
MyTest := (Form1.Controls[i] as TEdit).Text;
/*
I don't do another for cicle
if Form1.Controls[i] as TPanel) then
Begin
For ...
end;
*/
...
end;
end;
My problem is ...how do i know if the Controls[i] selected have a child
controls ?
My Structure
TPageControl
--TTabSheet
--TPanel
-- TPageControl
--TTabSheet
I dont make a lot of For cicles...
I have 40 components with another component
to panel with another tpanel...with TPageControl....etc...
etc...etc..
Sorry for my bad english...
Thanks in advance
Marco.
Italy
 
 

Re:Form and ControlCount

"Balin" <XXXX@XXXXX.COM>writes:
Quote
My problem is ...how do i know if the Controls[i] selected have a child
controls ?
Ask if their ControlCount property is non-zero.
Or you could use the Components array for the form.
Good luck.
Kurt
 

Re:Form and ControlCount

"Balin" <XXXX@XXXXX.COM>writes
Quote

My problem is ...how do i know if the Controls[i] selected have a child
controls ?
My Structure

TPageControl
--TTabSheet
--TPanel
-- TPageControl
--TTabSheet

I dont make a lot of For cicles...

I have 40 components with another component
to panel with another tpanel...with TPageControl....etc...
etc...etc..
Here is the procedure that I use. It will find any control that exists
whether it is on the passed parent or one of it is children. Pass the form as
the first parameter (or any other container control) and the name of the
component you are looking for as the second argument. (Admittedly, the empty
Try/Finally only hides any exceptions it may encounter :)
function FindAnyControl(obj: TWinControl; s: string): TComponent;
var
x: integer;
begin
result := nil;
try
for x := 0 to obj.ComponentCount-1 do begin
if (AnsiCompareText(s, obj.Components[x].Name) = 0) then
result := obj.Components[x]
else if obj.Components[x] is TWinControl then
result := FindAnyControl(TWinControl(obj.Components[x]), s);
if (result <>nil) then
break;
end;
finally
end;
end;
HTH
--
Woody (TMW)
Freeware Page: users.eonet.net/woodytmw
All computers wait at the same speed.