代码之家  ›  专栏  ›  技术社区  ›  norgepaul

在Delphi编辑器中更改TCollectionItem的标签

  •  4
  • norgepaul  · 技术社区  · 17 年前

    我正在处理的一个组件使用TCollection来保存指向其他组件的链接。在设计器中编辑项目时,它们的标签看起来像这样:

    0 - TComponentLink
    1 - TComponentLink
    2 - TComponentLink
    3 - TComponentLink
    

    如何添加有意义的标签(可能是链接组件的名称)?例如

    0 - UserList
    1 - AnotherComponentName
    2 - SomethingElse
    3 - Whatever
    

    作为奖励,你能告诉我如何在双击组件时显示集合编辑器吗?

    2 回复  |  直到 14 年前
        1
  •  5
  •   norgepaul    16 年前

    function TMyCollectionItem.GetDisplayName: string; 
    begin 
      Result := 'My collection item name'; 
    end;
    

    要在双击非可视化组件时显示集合编辑器,您需要覆盖TComponentEditor编辑过程。

    TMyPropertyEditor = class(TComponentEditor)
    public
      procedure Edit; override; // <-- Display the editor here
    end;
    

    RegisterComponentEditor(TMyCollectionComponent, TMyPropertyEditor);
    
        2
  •  1
  •   Mason Wheeler    17 年前

    编辑器中显示的名称存储在项目的DisplayName属性中。尝试在创建链接时将代码设置为这样:

    item.DisplayName := linkedItem.Name;