Using C++ Builder 10.4 Community edition, I have a TGroupBox populated with some TCheckbox and TButton controls. I want to iterate over the TGroupBox to get the state of each TCheckBox. How can I do this?
I tried this:
auto control = groupBxLB->Controls;
for( uint8_t idx = 0; idx < groupBxLB->ChildrenCount; idx++) {
if( control[idx] == TCheckBox) {
//get the state of the TCHeckBox
}
}
but no success.
Does anybody have an idea how I can do this?
The
TWinControl::Controlsproperty is not an object of its own, so you can't assign it to a local variable, the way you are trying to.Also, there is no
ChildrenCountproperty inTWinControl. The correct property name isControlCountinstead.The C++ equivalent of Delphi's
isoperator in this situation is to usedynamic_cast(cppreference link) and check the result forNULL.Try this:
UPDATE:
You did not make it clear in your original question that you wanted a solution for FMX. What I posted above is for VCL instead. The FMX equivalent would look more like this: