Delphi Readonly TCollection在设计时

时间:2018-02-23 17:45:14

标签: delphi components design-time tcollection

我试图在Delphi XE5中为TCollection创建并注册自定义编辑器。我尝试了几件事,包括继承TCollectionProperty类。我认为它足以覆盖GetColOptions函数,如下所示:

function TMycollectionEditor.GetColOptions: TColOptions;
begin
  Result: = [];
end;

但没有任何事情发生,仍然可以添加,删除和移动项目。所以通过搜索更多,我找到了Edit函数的代码,并写了以下内容:

procedure TMycollectionEditor.Edit;
var
  ACollection: TCollection;
  APersistent: TPersistent;
begin
  APersistent: = GetComponent (0);

  while (APersistent <> nil) and not (APersistent is TComponent)
    APersistent: = GetPersistentOwner (APersistent);

  ACollection: = TCollection (TMy component (APersistent) .MyCollection);

  ShowCollectionEditorClass (Designer, GetEditorClass, TComponent (APersistent), ACollection, GetName, GetColOptions);
end;

这也没有改变本机编辑器的工作原理。

我做错了什么?这是一个很好的做法,做我想做的事情? 注意:我的目标与this帖子

不同

更新

我对可行的方法进行了临时更改(除了通过上下文菜单或双击[使用TCollection的继承属性的ExecuteVerb方法])

    procedure TMycollectionEditor.Edit;
    var
      ACollection: TCollection;
      APersistent: TPersistent;
    begin
      APersistent: = GetComponent (0);

      while (APersistent <> nil) and not (APersistent is TComponent)
        APersistent: = GetPersistentOwner (APersistent);

      ACollection: = TCollection (TMy component (APersistent) .MyCollection);
//    [update bellow]
      with ShowCollectionEditorClass (Designer, GetEditorClass, TComponent (APersistent), ACollection, GetName, GetColOptions) do
      begin
        AddCmd.Enabled := False;
        ListView1.DragMode := dmManual;
        ToolBar1.Visible := False;
        ToolBar2.Visible := False;
      end;

    end;

0 个答案:

没有答案