ave*_*ore 7 delphi components property-editor townedcollection
我创建了一个从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)
任何解决方案或不同的方法将不胜感激.
就我所知,你没有使用正确的编辑器.TDefaultEditor
这样描述:
一个编辑器,它为双击提供默认行为,该行为将遍历属性,查找要编辑的最合适的方法属性
这是一个编辑器,它通过使用新创建的事件处理程序将您放入代码编辑器来响应对表单的双击.想想当你双击一个TButton
并且你被放入OnClick
处理程序时会发生什么.
自从我写了一个设计时间编辑器以来已经很长时间了(我希望我的记忆在今天工作),但我相信你的编辑器应该来源于TComponentEditor
.为了显示您ShowCollectionEditor
从该ColnEdit
单元调用的集合编辑器.
你可以覆盖那里的Edit
方法TComponentEditor
和来电ShowCollectionEditor
.如果你想成为更高级的,作为替代,你可以声明一些动词用GetVerbCount
,GetVerb
和ExecuteVerb
.如果你这样做,那么你扩展上下文菜单,默认Edit
实现将执行动词0.
按照David的正确答案,我想提供完整的代码,该代码在设计时双击UI控件的特定属性时显示CollectionEditor.
type
TMyCustomPanel = class(TCustomPanel)
private
...
published
property MyOwnedCollection: TMyOwnedCollection read GetMyOwnedCollection write SetMyOwnedCollection;
end;
TMyCustomPanelEditor = class(TComponentEditor)
public
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;
procedure Register;
begin
RegisterComponentEditor(TMyCustomPanel, TMyCustomPanelEditor);
end;
function TMyCustomPanelEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
function TMyCustomPanelEditor.GetVerb(Index: Integer): string;
begin
Result := '';
case Index of
0: Result := 'Edit MyOwnedCollection';
end;
end;
procedure TMyCustomPanelEditor.ExecuteVerb(Index: Integer);
begin
inherited;
case Index of
0: begin
// Procedure in the unit ColnEdit.pas
ShowCollectionEditor(Designer, Component, TMyCustomPanel(Component).MyOwnedCollection, 'MyOwnedCollection');
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)