You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使自定义TFlowPanel组件的子控件在结构窗口中显示?

自定义TFlowPanel容器组件的设计时子控件显示问题

我正在基于TFlowPanel开发一款可作为其他控件容器的组件,需要支持在设计时和运行时(根据属性配置)添加控件,同时希望开发者在设计阶段能直接填充组件并通过代码访问其子控件。

我写了一个简单的测试组件,在Create方法里创建了一个TPanel并将其父级设为自定义组件。把组件放到窗体上后,能看到内部的TPanel,但结构窗口里它并没有显示为子控件。而直接在窗体上放置TFlowPanel并添加TPanel时,这个TPanel能正常在结构窗口里显示为子控件。

代码示例

type
  TMyFlowPanel = class(TFlowPanel)
  private
  ...

constructor TMyFlowPanel.Create(AOwner: TComponent);
var
  vPanel: TPanel;
begin
  inherited Create(AOwner);

  Self.Height := 99;
  Self.BevelKind := TBevelKind.bkFlat;

  vPanel := TPanel.Create(Self);
  vPanel.Parent := Self;
  vPanel.Caption := '***';
  vPanel.Height := 33;
  vPanel.Align := TAlign.alTop;

end;

测试用DFM文件内容

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 326
  ClientWidth = 619
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object MyFlowPanel1: TMyFlowPanel
    Left = 24
    Top = 24
    Width = 185
    Height = 99
    BevelKind = bkFlat
    Caption = 'MyFlowPanel1'
    TabOrder = 0
  end
  object FlowPanel1: TFlowPanel
    Left = 24
    Top = 144
    Width = 185
    Height = 145
    Caption = 'FlowPanel1'
    TabOrder = 1
    object Panel1: TPanel
      Left = 1
      Top = 1
      Width = 185
      Height = 41
      Caption = 'Panel1'
      TabOrder = 0
    end
  end
end

内容的提问来源于stack exchange,提问作者WpNodes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 10:53:13