delphidelphi-xe3toolsapi

Delphi, Editor for Button, preserve default click in IDE


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


Solution

  • I guess that your Editor was inherited from TComponentEditor ? if So , you need to call the default Edit function in order to generates OnClick event of your component inside your editor ExecuteVerb function . Note : the Edit function is empty in the TComponentEditor class .. So you need to use the IDefaultEditor interface to call the Edit function :

    First Method :

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

    Second Method :

    You have another way : You can inherite your Editor from TDefaultEditor class (and not from TComponentEditor) :

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

    But if you use the second method , you will lose your capability (Only when double click, other context menu will apear normaly ). i would prefer using the first method .