如何在设计时调用组件的属性编辑器
我创建了一个从 TCustomPanel 派生的组件。在该面板上,我有一个从 TOwnedCollection 派生的类的已发布属性。一切运行良好,单击该属性的对象检查器中的省略号将打开默认集合编辑器,我可以在其中管理列表中的 TCollectionItems。
TMyCustomPanel = class(TCustomPanel)
private
...
published
property MyOwnedCollection: TMyOwnedCollection read GetMyOwnedCollection write SetMyOwnedCollection;
end;
我还希望能够在设计时双击面板并默认打开集合编辑器。我首先创建一个从 TDefaultEditor 派生的类并注册它。
TMyCustomPanelEditor = class(TDefaultEditor)
protected
procedure EditProperty(const PropertyEditor: IProperty; var Continue: Boolean); override;
end;
RegisterComponentEditor(TMyCustomPanel, TMyCustomPanelEditor);
这似乎是在正确的时间运行的,但我当时不知道如何启动集合的属性编辑器。
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;
任何解决方案或不同的方法将不胜感激。
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;
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您没有使用正确的编辑器。
TDefaultEditor
的描述如下:这是一个编辑器,通过将您放入具有新创建事件的代码编辑器来响应表单上的双击处理程序。想象一下当您双击
TButton
并进入OnClick
处理程序时会发生什么。自从我编写设计时编辑器以来已经很长时间了(我希望今天我的记忆还可以),但我相信您的编辑器应该源自
TComponentEditor
。为了显示集合编辑器,您可以从ColnEdit
单元调用ShowCollectionEditor
。您可以重写
TComponentEditor
的Edit
方法,并从那里调用ShowCollectionEditor
。如果您想更高级,您也可以使用GetVerbCount
、GetVerb
和ExecuteVerb
声明一些动词。如果您这样做,那么您将扩展上下文菜单,并且默认的Edit
实现将执行动词 0。You aren't using the correct editor, so far as I can tell.
TDefaultEditor
is described thus: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 theOnClick
handler.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 callShowCollectionEditor
from theColnEdit
unit.You can override the
Edit
method ofTComponentEditor
and callShowCollectionEditor
from there. If you want to be more advanced, as an alternative you can declare some verbs withGetVerbCount
,GetVerb
andExecuteVerb
. If you do it this way then you extend the context menu and the defaultEdit
implementation will execute verb 0.根据 David 的正确答案,我想提供完整的代码,该代码显示在设计时双击 UI 控件的特定属性的 CollectionEditor。
Following David's correct answer, I would like to provide the completed code that shows the CollectionEditor for a specific property of a UI control when it is double-clicked at design-time.