7

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;

任意のソリューションまたは別のアプローチをいただければ幸いです。

4

2 に答える 2

10

私が知る限り、あなたは正しいエディタを使用していません。TDefaultEditorは次のように記述されます。

編集するのに最も適切なメソッド プロパティを探してプロパティを反復処理する、ダブルクリックの既定の動作を提供するエディタ

これは、フォームのダブルクリックに応答して、新しく作成されたイベント ハンドラーを使用してコード エディターにドロップするエディターです。a をダブルクリックしてハンドラーTButtonにドロップインするとどうなるか考えてみてください。OnClick

デザインタイム エディタを書いてからずいぶん経ちましたが (今日の記憶が正しければと思います)、エディタはTComponentEditor. コレクション エディタを表示するにはShowCollectionEditor、ユニットから呼び出しますColnEdit

Editのメソッドをオーバーライドして、そこからTComponentEditor呼び出すことができますShowCollectionEditor。より高度にしたい場合は、別の方法として、 と を使用していくつかの動詞を宣言GetVerbCountできGetVerbますExecuteVerb。このようにすると、コンテキスト メニューが拡張され、デフォルトのEdit実装では動詞 0 が実行されます。

于 2011-09-16T15:12:44.483 に答える
5

David の正解に続いて、UI コントロールの特定のプロパティをデザイン時にダブルクリックしたときに CollectionEditor を表示する完成したコードを提供したいと思います。

type
  TMyCustomPanel = class(TCustomPanel)
  private
  ...
  published
    property MyOwnedCollection: TMyOwnedCollection read GetMyOwnedCollection write SetMyOwnedCollection;
  end;


  TMyCustomPanelEditor = class(TComponentEditor)
  public
    function GetVerbCount: Integer; override;
    function GetVerb(Index: Integer): string; override;
    procedure ExecuteVerb(Index: Integer); override;
  end;


procedure Register;
begin
  RegisterComponentEditor(TMyCustomPanel, TMyCustomPanelEditor);
end;

function TMyCustomPanelEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

function TMyCustomPanelEditor.GetVerb(Index: Integer): string;
begin
  Result := '';
  case Index of
    0: Result := 'Edit MyOwnedCollection';
  end;
end;

procedure TMyCustomPanelEditor.ExecuteVerb(Index: Integer);
begin
  inherited;
  case Index of
    0: begin
          // Procedure in the unit ColnEdit.pas
          ShowCollectionEditor(Designer, Component, TMyCustomPanel(Component).MyOwnedCollection, 'MyOwnedCollection');
       end;
  end;
end;
于 2011-09-18T14:06:18.527 に答える