I’m using C++ Builder XE, and have a problem with the “Showing” property of a TCheckBox.
I have a TForm (ChannelConfigForm), in which there is a TGroupBox (AlarmsGroupBox), in which there is a TCheckBox (A4_en_Xbox).
Sometimes, I cannot see some of the controls on the form.
According to the help documentation :
“If the Visible properties of a component and all the parents in its parent hierarchy are true, Showing is guaranteed to be true. If one of the parents containing the control has a Visible property value of false, Showing may be either true or false.
Showing is a read-only property.”
To find out what’s happening, I wrote the following function to debug the program :
(note : debugf in this function is simply a debug statement I wrote that works similar to printf, which writes debugging stuff to a form)
void ShowParentTree(TControl *Control)
{
wchar_t Name[32];
static int level=0;
TWinControl *wc;
level++;
if (level==1)
debugf(L"Parents of control \"%s\" (%s) :",
Control->Name.c_str(),
Control->ClassName().c_str());
// Display what Control has as parents and if they're visible and showing
debugf(L"level %d : %s->Visible = %s",level,
Control->Name.c_str(),
Control->Visible?L"true":L"false");
wc=(TWinControl *)Control;
debugf(L"level %d : %s->Showing = %s",level,
wc->Name.c_str(),
wc->Showing?L"true":L"false");
if (Control->Parent)
ShowParentTree((TControl *)Control->Parent);
level--;
}
Sometimes when I show the ChannelConfigForm I get the following :
Parents of control "A4_en_Xbox" (TCheckBox) :
level 1 : A4_en_Xbox->Visible = true
level 1 : A4_en_Xbox->Showing = false
level 2 : AlarmsGroupBox->Visible = true
level 2 : AlarmsGroupBox->Showing = true
level 3 : ChannelConfigForm->Visible = true
level 3 : ChannelConfigForm->Showing = true
which I understand as meaning that the A4_en_Xbox->Showing property is false when I think it should be true.
Check what
A4_en_Xbox->HandleAllocated()returns.Showingwill be false ifHandleAllocated()returns false. The VCL does not guarantee that a TWinControl-derived component always has anHWNDallocated at all times. Sometimes it does freeHWNDs internally and recreates them when needed.Also, your code has a small logic bug in it. Not all
TControldescendants are derived fromTWinControl, but your code assumes the inputTControlis always aTWinControldescendant. You need to check for that so you can avoid access theShowingproperty for non-TWinControlcontrols. You can also do away with the recursion completely, just use a simply loop instead: