Question

I have a single TForm with a single TVertScrollBox. I have added 6 TPanels as children of this TVertScrollBox.

I would like to iterate over each of these panels and check the Tag property of each, but I can't find the correct method to do so.

For testing, I've added an OnClick event handler for one of the panels that contains the following code:

void __fastcall TForm1::Panel1Click(TObject *Sender)
{
    int i;

    for (i = 0; i < this->VertScrollBox1->ChildrenCount; ++i)
    {
        ShowMessage("Child: " + this->VertScrollBox1->Children[i]->Name);
    }

    for (i = 0; i < this->VertScrollBox1->ComponentCount; ++i)
    {
        ShowMessage("Component: " + this->VertScrollBox1->Components[i]->Name);
    }
}

It seems the ChildrenCount property always returns 2, and the Name displayed by ShowMessage for each of these children is an empty string, even though each panel has a unique Name property.

The ComponentCount property always returns 1, and again- the displayed Name is always an empty string.

Can someone tell me which properties or methods to use to iterate over these children?

Était-ce utile?

La solution

Children & ChildrenCount are the correct properties to use but it sounds like your panels are being stored in a container stored within the scrollbox. (I've seen this in other components and I'm not at my dev machine to research).

Check the Classnames of the two children, and what their children are. When you've astablished which child (identified by ClassName) is the container, you'll know how to drill down to your panels.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top