2

I have to know number of controls placed inside a TFramedScrollBox control container.

When I use the code TFramedScrollBox.ControlsCount. It always return the value 2. Why?

I want to use the for loop and iterate through each control and set a few properties. As the number of controls returned is always 2 I am not able to iterate through each control contained inside TFramedScrollBox.

How to solve this problem?

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Yogi Yang 007
  • 5,147
  • 10
  • 56
  • 77

1 Answers1

9

The FMX TFramedScrollBox (as well as TScrollBox) has a property Content: TScrollContent which holds the added controls. Use Content.Controls to list the controls.

For example:

for i := 0 to FramedScrollBox1.Content.ControlsCount-1 do
  Memo1.Lines.Add(FramedScrollBox1.Content.Controls[i].Name);

Edit:

To answer the question "why TFramedScrollBox.ControlsCount always returns 2?:

The two components indicated by TFramedScrollBox.ControlsCount and which can be accessed via TFramedScrollBox.Controls are a TLayout and a TScrollContent. The latter being the Content that holds the child controls.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • This only answers 1/2 of the question asked. It provides a solution, but it would also be helpful to address the WHY about `ControlsCount` always being 2, and what those 2 controls actually are. – Remy Lebeau Jul 16 '21 at 14:34
  • @RemyLebeau Added answer for the first half of the question. – Tom Brunberg Jul 16 '21 at 18:42