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

nor*_*aul 4 delphi delphi-2009 tcollectionitem

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

0 - TComponentLink
1 - TComponentLink
2 - TComponentLink
3 - TComponentLink
Run Code Online (Sandbox Code Playgroud)

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

0 - UserList
1 - AnotherComponentName
2 - SomethingElse
3 - Whatever
Run Code Online (Sandbox Code Playgroud)

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

nor*_*aul 5

要显示有意义的名称,请覆盖GetDisplayName:

function TMyCollectionItem.GetDisplayName: string; 
begin 
  Result := 'My collection item name'; 
end;
Run Code Online (Sandbox Code Playgroud)

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

TMyPropertyEditor = class(TComponentEditor)
public
  procedure Edit; override; // <-- Display the editor here
end;
Run Code Online (Sandbox Code Playgroud)

...并注册编辑器:

RegisterComponentEditor(TMyCollectionComponent, TMyPropertyEditor);
Run Code Online (Sandbox Code Playgroud)