0

我正在尝试TCollection在 Delphi XE5 中创建和注册自定义编辑器。我尝试了几件事,包括继承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;

这也没有改变原生编辑器的工作。

我究竟做错了什么?这是做我想做的事情的好习惯吗?注意:我的目标和这篇文章不一样

更新

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

    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;
4

0 回答 0