加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 04:16:02 所属栏目:大数据 来源:网络整理
导读:我创建了一个从TCustomPanel派生的组件.在该面板上,我有一个派生自TOwnedCollection的类的已发布属性.一切运行良好,单击该属性的对象检查器中的省略号将打开默认的集合编辑器,我可以在其中管理列表中的TCollectionItems. TMyCustomPanel = class(TCustomPane
我创建了一个从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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读