El 06/04/2017 a las 15:50, Goran Ekstrom escribió:
I am trying to get the pointers to all controls placed on a Container, in this case a TPanel.
I use this code:
for (int i = 0; ii < Container->ControlCount; ii++)
Is this a typo? You are declaring "i" as index but you are using "ii"
{
TRadioButton *TheButton = (TRadioButton *)Container->Controls[ii]);
Is the last ")" another typo?
.... // Do something
}
The Container->ControlCount property shows the right number of controls but...
TRadioButton *TheButton = (TRadioButton *)Container->Controls[ii]);
... only works for the first control (Container->Controls[0]), then it either hangs or I get NULL.
How do I iterate through the controls in a container?
Regards
Goran
This works for me in 10.1 Berlin if the panel contains TRadioButton
controls only:
for (int ii = 0; ii < Container->ControlCount; ii++)
{
TRadioButton *TheButton= (TRadioButton *)Container->Controls[ii];
}
If you have more of one type of control in panel you should do it this way:
for (int ii = 0; ii < Container->ControlCount; ii++)
{
TControl *Ctrl= Container->Controls[ii];
if (TRadioButton *TheButton= dynamic_cast<TRadioButton*>(Ctrl))
{
// Use TheButton as needed
}
/*
else if (TLabel *TheLabel= dynamic_cast<TLabel*>(Ctrl))
{
// Use TheLabel as needed
}
else ...
*/
}
Connect with Us