Question

I've made a Component Editor for my custom tLabel. Double clicking works fine, but right clicking on the component and selectind the corresponding Verb does nothing. The menu item is enabled, but the ExecuteVerb procedure is not triggered.

Follows the code:

unit LabelComponentEditor;

interface

uses
  Classes, DesignerTypes, DesignMenus, Dialogs,  
  DesignEditors, DesignIntf, Forms, Menus,
  CustomLabel;

type
  tLabelComponentEditor = class(tComponentEditor)
  private
    procedure Edit; override;
    procedure ExecuteVerb(Index: Integer);
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure PrepareItem(Index:  Integer; const aItem : iMenuItem); override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponentEditor (tCustomLabel, tLabelComponentEditor);
end;

procedure tLabelComponentEditor.Edit;
begin
  inherited;
  frmLabelDialog := tfrmLabelDialog.Create (Application);
  frmLabelDialog.ShowModal;
  frmLabelDialog.Free;
end; { Edit }

procedure tLabelComponentEditor.ExecuteVerb(Index: Integer); 
begin
  inherited;
  frmLabelDialog := tfrmLabelDialog.Create (Application);
  case Index of
    0 : begin
      frmLabelDialog.ShowModal;
      frmLabelDialog.Free;
    end;
  end;
end; { ExecuteVerb }

function tLabelComponentEditor.GetVerb (Index: Integer) : string;
begin
  case Index of
    0 : Result := 'Edit component'; // checked: this is executed
  end;
end; { GetVerb }

function tLabelComponentEditor.GetVerbCount : Integer;
begin
  Result := 1; // checked: this is executed
end; { GetVerbCount }

procedure tLabelComponentEditor.PrepareItem(Index: Integer; const aItem: iMenuItem);
begin
  case Index of
    0 : aItem.Enabled := True; // to see if 'ExecuteVerb' should trigger 
                               //   but in fact, made no difference
  end;
end; { PrepareItem }

end.
Was it helpful?

Solution

You did not specify override on your ExecuteVerb() method. Double-clicking calls the Edit() method, which you did override.

Also, since you only have 1 verb defined, you don't need to use case statements in your methods, since the Index will always be 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top