如何枚举TCategoryPanel持有的所有控件?

科学的名字

我有一个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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章