0

XE3 Prof, Win64.

I created a new Button component, based on TButton.

It have a special menu in IDE, named "Set Button Style".

procedure Register;
begin
    RegisterComponents('SComps', [TSAButton]);
    RegisterComponentEditor(TSAButton, TSAButtonEditor);
end;

procedure TSAButtonEditor.ExecuteVerb(Index: Integer);
begin
    Set_Style(TSAButton(Component));
end;

function TSAButtonEditor.GetVerb(Index: Integer): string;
begin
    Result := 'Set Button Style';
end;

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

The button's have special click in IDE - the double click on the component generates OnClick in my code.

After I installed my editor menu, this capability lost, because IDE calls my function, and not the original (the default code generating).

How can I restore this capability in my button with preserving my menu too?

Thanks for every info!

dd

4

1 回答 1

0

我猜您的 Editor 是从 TComponentEditor 继承的?如果是这样,您需要调用默认的 Edit 函数,以便在您的编辑器 ExecuteVerb 函数中生成组件的 OnClick 事件。注意:TComponentEditor类中的Edit函数是空的。所以你需要使用IDefaultEditor接口来调用Edit函数:

第一种方法:

procedure TYourEditor.ExecuteVerb(Index: Integer);
var
  DefEditor: IDefaultEditor;
begin
  DefEditor := TDefaultEditor.Create(Component, Designer);
  DefEditor.Edit;
  case Index of
    0:
      // DoSomething !!
      // ...
      // ...
    end;
      //...
end;

第二种方法:

您还有另一种方法:您可以从 TDefaultEditor 类(而不是 TComponentEditor)继承您的编辑器:

 TYourEditor = class(TDefaultEditor)
  .....
procedure TYourEditor.ExecuteVerb(Index: Integer);
begin
  inherited;
end;

但是如果你使用第二种方法,你会失去你的能力(只有双击,其他上下文菜单才会正常出现)。我更喜欢使用第一种方法。

于 2013-10-07T14:28:56.163 回答