XE3 教授,Win64。
我创建了一个新的按钮组件,基于 TButton。
它在 IDE 中有一个特殊的菜单,名为"设置按钮样式"。
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;
该按钮在 IDE 中具有特殊单击 - 双击组件会在我的代码中生成 OnClick。
安装编辑器菜单后,此功能丢失了,因为 IDE 调用我的函数,而不是原始函数(默认代码生成)。
如何在保留菜单的同时在按钮中恢复此功能?
感谢您提供的所有信息!
日嘎
我猜你的编辑器是从 TComponentEditor 继承的?如果是这样,则需要调用默认的 Edit 函数,以便在编辑器 ExecuteVerb 函数中生成组件的 OnClick 事件。注意:编辑函数在 TComponentEditor 类中为空。所以你需要使用 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;
但是如果你使用第二种方法,你将失去你的能力(只有双击时,其他上下文菜单才会正常)。我更喜欢使用第一种方法.