我为自定义Component Editor
制作了tLabel
。双击工作正常,但右键单击组件并选择相应的Verb
不执行任何操作。菜单项已启用,但未触发ExecuteVerb
过程。
遵循以下代码:
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.
答案 0 :(得分:2)
您未在override
方法上指定ExecuteVerb()
。双击调用您Edit()
的{{1}}方法。
此外,由于您只定义了1个动词,因此您不需要在方法中使用override
语句,因为case
将始终为0。