我有一个 TCategoryPanelGroup,其中包含一个 TCategoryPanel(名为 CatPan)。 CatPan 包含 3 个列表框。
我想自动调整 CatPan 的大小以匹配它包含的 3 个列表框的高度。但 CatPan 没有 AutoSize 属性。因此,我需要枚举列表框来获取它们的高度。
但是,当我尝试枚举 3 个列表框时,我什么也没得到:
for i= 0 to CatPan->ControlCount-1 do CatPan[i].Height;
因为 CatPan.ControlCount 返回 1 而不是 3!看起来 CapPan 不是列表框的父级。这样做可能是为了能够执行折叠/展开动画。
我调用了lbox1->Parent->Name(lbox1是列表框之一)来查看谁是它的父级,但它返回一个空字符串。
您缺少 TCategoryPanel 在其构造函数中创建 TCategoryPanelSurface 对象作为其子对象,因此所有控件都进入 TCategoryPanelSurface 对象而不是 TCategoryPanel。
在 C++ Builder 中,它是这样的:
ShowMessage(ListBox1->Parent->ClassName()); //you can see actual parent class here
TCategoryPanelSurface * Surface;
Surface = dynamic_cast <TCategoryPanelSurface *> (CatPan->Controls[0]);
ShowMessage(Surface->ControlCount);
ShowMessage(Surface->Controls[0]->Name); //you should use loop here to iterate through controls
在德尔福:
var
Surface: TCategoryPanelSurface;
I: Integer;
begin
Surface := CatPan.Controls[0] as TCategoryPanelSurface;
for I := 0 to Surface.ControlCount - 1 do
begin
ShowMessage(Surface.Controls[I].Name);
end;
end;