IDE 插件禁用插入键

Ali*_*ter 3 delphi plugins

我一直在使用 Delphi (10.3 Rio) 的 IDE 插件来禁用插入键(有人真的使用过类型转换模式吗?)。

它可以很好地安装到 IDE 中,但是如果我卸载它,当我按下插入键时会发生异常。

有人可以帮我从这里出去吗?

这是更新的源代码:(我已经添加了定稿部分,仍然出现错误)

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.
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Rem*_*eau 7

您需要调用IOTAKeyboardServices.RemoveKeyboardBinding()during finalization,将返回的值传递给它IOTAKeyboardServices.AddKeyboardBinding()(您当前未保存)。

请查看David Hoyle 博客中的第 4 章:键绑定和调试工具,其中提供了使用 OpenTools API 的键盘绑定向导示例。