如何让组件编辑器在双击时执行原始处理程序?

How to make a component editor perform original handler on double click?

我已经为我的自定义控件构建了一个自定义组件编辑器 (TComponentEditor)。我正在实现右键单击上下文菜单,这意味着默认情况下,在设计时双击控件会执行第一个上下文菜单项。但是,双击后,我不希望发生这种情况。我想要创建 OnClick 事件处理程序的原始行为。

在重写此组件编辑器的 Edit 过程时,我尝试了使用和不使用 inherited。如果我包含它,双击会执行上下文菜单中的第一项。如果我不包括 inherited,那么双击控件时什么也不会发生。在添加这个组件编辑器之前,双击会自动生成一个OnClick事件处理程序,我自己没有实现。

{ TFontButtonEditor }

type
  TFontButtonEditor = class(TComponentEditor)
  private
    FForm: TfrmFontButtonEditor;
    FBtn: TFontButton;
    procedure ExecEditor;
  protected
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): String; override;
    function GetVerbCount: Integer; override;
  public
    constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
    destructor Destroy; override;
    procedure Edit; override;
  end;

constructor TFontButtonEditor.Create(AComponent: TComponent;
  ADesigner: IDesigner);
begin
  inherited;
  FBtn:= TFontButton(AComponent); //Reference instance of control
  FForm:= TfrmFontButtonEditor.Create(nil); //Create editor form instance
end;

destructor TFontButtonEditor.Destroy;
begin
  FForm.Free;
  inherited;
end;

procedure TFontButtonEditor.Edit;
begin
  //Executed on double-click, but I don't want to...
  //inherited;
end;

procedure TFontButtonEditor.ExecEditor;
begin
  FForm.FFont.Assign(FBtn.Image.Font);
  FForm.ImageChar:= FBtn.Image.Text;
  //More assignments
  case FForm.ShowModal of
    mrOK: begin
      FBtn.Image.Font.Assign(FForm.FFont);
      FBtn.Image.Text:= FForm.ImageChar;
      //More assignments
    end;
    else begin
      //Cancelled
    end;
  end;
end;

procedure TFontButtonEditor.ExecuteVerb(Index: Integer);
begin
  case Index of
    0: begin
      ExecEditor;
      //Also executed on double-click, don't want it to...
    end;
    1: begin
      MessageDlg('Font Button Control - XXXXX', mtInformation, [mbOK], 0);
    end;
  end;
end;

function TFontButtonEditor.GetVerb(Index: Integer): String;
begin
  case Index of
    0: Result:= '&Edit Font Button';
    1: Result:= '&About Font Button';
  end;
end;

function TFontButtonEditor.GetVerbCount: Integer;
begin
  Result:= 2;
end;

如何使用组件编辑器双击此自定义控件来执行老式 OnClick 事件处理程序,而不是尝试执行组件编辑器?

下降自 TDefaultEditor instead of TComponentEditor

(TDefaultEditor 通过调用 OnCreateOnChangeOnClick [=24= 的 Edit 方法,用您的意愿替换 Edit 方法],或者它找到的第一个事件 属性。属性 的 Edit 方法在 TMethodProperty.SetValueDesigner.CreateMethod 中创建了事件处理程序,并进行了一些关于继承形式、现有名称的检查等...)