如何在设计时调用组件的属性编辑器
我已经创建了一个派生自TCustomPanel的组件。在该面板上,我有一个派生自TOwnedCollection的类的已发布属性。所有这些都正常工作,单击该属性的对象检查器中的省略号可以打开默认集合编辑器,我可以在其中管理列表中的TCollectionItem。
I have created a component derived from TCustomPanel. On that panel I have a published property of a class derived from TOwnedCollection. All is working well and clicking the ellipsis in the object inspector for that property opens the default collection editor where I can manage the TCollectionItems in the list.
TMyCustomPanel = class(TCustomPanel)
private
...
published
property MyOwnedCollection: TMyOwnedCollection read GetMyOwnedCollection write SetMyOwnedCollection;
end;
我也希望能够在设计时双击面板,收藏编辑器默认打开。我已经开始创建一个派生自TDefaultEditor并注册的类。
I would also like to be able to double-click on the panel at design-time and have the collection editor open up by default. I've started off by creating a class derived from TDefaultEditor and registering it.
TMyCustomPanelEditor = class(TDefaultEditor)
protected
procedure EditProperty(const PropertyEditor: IProperty; var Continue: Boolean); override;
end;
RegisterComponentEditor(TMyCustomPanel, TMyCustomPanelEditor);
这似乎是在正确的时间运行,但我坚持如何启动属性编辑器当时的集合。
This seems to be run at the right time, but I'm stuck on how to launch the property editor for the collection at that time.
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;
任何解决方案或不同的方法将不胜感激。
Any solution or different approach would be appreciated.
据我所知,你没有使用正确的编辑器。 TDefaultEditor
的描述如下:
You aren't using the correct editor, so far as I can tell. TDefaultEditor
is described thus:
点击将遍历属性,查找最合适的方法属性来编辑
An editor that provides default behavior for the double-click that will iterate through the properties looking the the most appropriate method property to edit
这是一个编辑器,响应双击点击通过将一个新创建的事件处理程序放入代码编辑器中。想想当您双击 TButton
时,会发生什么,您将被删除到 OnClick
处理程序。
This is an editor that responds to double clicks on the form by dropping you into the code editor with a newly created event handler. Think of what happens when you double click a TButton
and you are dropped in to the OnClick
handler.
自从我写了一个设计时间编辑器(我希望我的记忆今天工作)已经很久了,但我相信你的编辑器应该从 TComponentEditor
。为了显示收藏编辑器,您可以从 ColnEdit
单元中调用 ShowCollectionEditor
。
It's been a long time since I wrote a design time editor (I hope my memory is working today) but I believe your editor should be derived from TComponentEditor
. In order to show the collection editor you call ShowCollectionEditor
from the ColnEdit
unit.
您可以覆盖编辑
方法 TComponentEditor
并调用 ShowCollectionEditor
从那里。如果你想要更高级,作为替代,你可以用 GetVerbCount
, GetVerb
和 ExecuteVerb
。如果你这样做,那么你可以扩展上下文菜单,默认的编辑
实现将执行动词0。
You can override the Edit
method of TComponentEditor
and call ShowCollectionEditor
from there. If you want to be more advanced, as an alternative you can declare some verbs with GetVerbCount
, GetVerb
and ExecuteVerb
. If you do it this way then you extend the context menu and the default Edit
implementation will execute verb 0.