我创建了一个从TCustomPanel派生的组件.在该面板上,我有一个派生自TOwnedCollection的类的已发布属性.一切运行良好,单击该属性的对象检查器中的省略号将打开默认的集合编辑器,我可以在其中管理列表中的TCollectionItems.
TMyCustomPanel = class(TCustomPanel)
private
...
published
property MyOwnedCollection: TMyOwnedCollection read GetMyOwnedCollection write SetMyOwnedCollection;
end;
Run Code Online (Sandbox Code Playgroud)
我还希望能够在设计时双击面板并默认打开集合编辑器.我开始创建一个派生自TDefaultEditor的类并注册它.
TMyCustomPanelEditor = class(TDefaultEditor)
protected
procedure EditProperty(const PropertyEditor: IProperty; var Continue: Boolean); override;
end;
RegisterComponentEditor(TMyCustomPanel, TMyCustomPanelEditor);
Run Code Online (Sandbox Code Playgroud)
这似乎是在正确的时间运行,但我仍然坚持如何在当时启动集合的属性编辑器.
procedure TMyCustomPanelEditor.EditProperty(const PropertyEditor: IProperty; var Continue: Boolean);
begin
inherited;
// Comes in here on double-click of the panel
// How to launch collection editor here for property MyOwnedCollection?
Continue := false;
end;
Run Code Online (Sandbox Code Playgroud)
任何解决方案或不同的方法将不胜感激.
我正在尝试使用集合属性创建自定义组件.但是,如果我在设计时通过单击对象检查器中的"..."按钮尝试打开集合编辑器,则不会发生任何事情.我错过了什么?
这是我的TCollection后代:
TMyCollection = class(TOwnedCollection)
private
function GetItem(Index: Integer): TMyCollectionItem;
procedure SetItem(Index: Integer; const Value: TMyCollectionItem);
public
function Add : TMyCollectionItem;
property Items[Index: Integer]: TMyCollectionItem read GetItem write SetItem;
end;
Run Code Online (Sandbox Code Playgroud)
和项目:
TMyCollectionItem = class(TCollectionItem)
private
FValue: integer;
protected
function GetDisplayName: string; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
property Value : integer read FValue write FValue;
end;
Run Code Online (Sandbox Code Playgroud)