【发布时间】:2020-05-12 22:27:47
【问题描述】:
我一直在使用 Delphi (10.3 Rio) 的 IDE 插件来禁用插入键(有人真的使用过输入模式吗?)。
它可以很好地安装到 IDE 中,但是如果我卸载它,当我按下插入键时会发生异常。
谁能帮帮我?
这里是更新的来源: (我添加了finalization部分,还是报错)
unit MyBinding;
interface
procedure Register;
implementation
uses Windows, Classes, SysUtils, ToolsAPI, Vcl.Menus;
type
TLearnDelphiKeyBinding = class(TNotifierObject, IOTAKeyboardBinding)
private
procedure DoNothing(const Context: IOTAKeyContext; KeyCode: TShortCut; var BindingResult: TKeyBindingResult);
public
function GetBindingType: TBindingType;
function GetDisplayName: string;
function GetName: string;
procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices);
end;
var
LearnDelphiKeyBindingIndex : integer = 0;
procedure Register;
begin
LearnDelphiKeyBindingIndex := (BorlandIDEServices as IOTAKeyBoardServices).AddKeyboardBinding(TLearnDelphiKeyBinding.Create);
end;
procedure TLearnDelphiKeyBinding.BindKeyboard(const BindingServices: IOTAKeyBindingServices);
begin
BindingServices.AddKeyBinding([ShortCut(VK_INSERT, [])], DoNothing, nil);
end;
function TLearnDelphiKeyBinding.GetBindingType: TBindingType;
begin
Result := btPartial;
end;
function TLearnDelphiKeyBinding.GetDisplayName: string;
begin
Result := 'Disable Insert';
end;
function TLearnDelphiKeyBinding.GetName: string;
begin
Result := 'LearnDelphi.DisableInsert';
end;
procedure TLearnDelphiKeyBinding.DoNothing(const Context: IOTAKeyContext;
KeyCode: TShortCut; var BindingResult: TKeyBindingResult);
begin
BindingResult := krHandled;
end;
initialization
finalization
if LearnDelphiKeyBindingIndex > 0 then
(BorlandIDEServices as IOTAKeyboardServices).RemoveKeyboardBinding(LearnDelphiKeyBindingIndex);
end.
【问题讨论】:
-
"有人真的使用过打字模式吗?"我每天使用它很多次。这是一个实际的例子(有点下,在它自己的部分下):rejbrand.se/rejbrand/article.asp?ItemIndex=479
-
@AndreasRejbrand 不完全是一个引人注目的例子,但我会记住它——也许有一天我会记得使用它——假设我没有禁用 Insert 键。