Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: ChildrenCount [and ComponentCount] seem to NOT work


This question is answered.


Permlink Replies: 2 - Last Post: Dec 16, 2014 5:07 PM Last Post By: Free Dorfman
Free Dorfman

Posts: 16
Registered: 1/6/15
ChildrenCount [and ComponentCount] seem to NOT work  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2014 11:03 AM
Simple FMX app. TButton & TScrollBox.

I put (in code) 5 CheckBoxes in/on ScrollBox1 & then look at ScrollBox1.ChildrenCount, expecting it to be 5, but it's 2.

NOTE that P being declared as a TControl or a TScrollBox changes nothing.

ALSO NOTE that changing the 5 to, say 50, also changes nothing.

ONE MORE: Commenting out the creation of the CheckBoxes (i.e.
changing the 5 to a 0) also changes nothing.

The TScrollBox seems to have 2 children & 1 component as soon
as it's created, and NEVER "gets" any more??!?

#######################################################

procedure TForm1.Button1Click(Sender: TObject);
var
x: integer;
P: TControl; //TScrollBox
CHK: TCheckBox;
begin
P := ScrollBox1;

for x := 1 to 5 do
begin
CHK := TCheckBox.Create(Self);
CHK.Parent := P;
CHK.Tag := integer(x);
CHK.SetBounds(10,10 + 20 * Pred(x),40,CHK.Height);
CHK.Text := '# ' + x.ToString;
end;

ShowMessage('ScrollBox1 has ' +
ScrollBox1.ChildrenCount.ToString + ' children; ' +
ScrollBox1.ComponentCount.ToString + ' components');
end;

#######################################################

NOTE: I'm a very savvy Delphi 6 user. This was a [working] no-
brainer with [TWinControl.]ControlCount under D6.

#######################################################

Any thoughts here greatly appreciated.

Edited by: Free Dorfman on Dec 16, 2014 11:07 AM
Eli M

Posts: 1,346
Registered: 11/9/13
Re: ChildrenCount [and ComponentCount] seem to NOT work
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2014 4:00 PM   in response to: Free Dorfman in response to: Free Dorfman
Firemonkey has styles. The style components show up in those counts. So what you are seeing are the styled components. If you display the ClassName from each you will see what they are. You can drill down into those components to get to what you actually want. Or there may be another count property that gives it to you directly.
Free Dorfman

Posts: 16
Registered: 1/6/15
Re: ChildrenCount [and ComponentCount] seem to NOT work  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2014 5:07 PM   in response to: Eli M in response to: Eli M
Thanks Eli. I see the different [Children]ClassNames. FYI: The TScrollBox was problematic. A TPanel isn't in the same way. HOWEVER, you are correct in sending me to the ClassNames. Thanks Again!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02