delphi – 如何在设计时调用组件的属性编辑器

我创建了一个从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;

任何解决方案或不同的方法将不胜感激.

解决方法

据我所知,您没有使用正确的编辑器.因此描述了TDefaultEditor:

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处理程序时会发生什么.

我写了一个设计时间编辑器已经很久了(我希望我的记忆今天正常工作),但我相信你的编辑器应该来自TComponentEditor.为了显示集合编辑器,您可以从ColnEdit单元调用ShowCollectionEditor.

您可以覆盖TComponentEditor的Edit方法并从那里调用ShowCollectionEditor.如果你想更高级,可以使用GetVerbCount,GetVerb和ExecuteVerb声明一些动词.如果你这样做,那么你扩展上下文菜单,认的Edit实现将执行动词0.

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...