ertx
ertx

Reputation: 1544

Delphi: How to create an extra design-time menu for a custom component?

I've recently recompiled TDBGrid component, to implement several custom functions, altho i've noticed that the feature of extra design-time context menu item "Columns editor" is gone now.

http://i121.photobucket.com/albums/o210/R33_m/Columns.png

I've failed to find any code which creates this menu in original Vcl.DBGrids unit and had a really bad luck looking for a solution online on how to do this.

This also applies to double-clicking. It used to call Columns Editor, now it just creates OnCellClick event.

Upvotes: 2

Views: 1297

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

In your design time package for the component, implement a component editor:

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

procedure TMyComponentEditor.ExecuteVerb(Index: Integer);
begin
  case Index of
  0:
    Beep;
  end;
end;

function TMyComponentEditor.GetVerb(Index: Integer): string;
begin
  Result := 'Beep';
end;

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

You need to register this component editor also. Call RegisterComponentEditor in your Register procedure to do so:

RegisterComponentEditor(TMyComponent, TMyComponentEditor);

Upvotes: 5

Related Questions