我一直在为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.


delphi - IDE插件可禁用插入键-LMLPHP

最佳答案

您需要在IOTAKeyboardServices.RemoveKeyboardBinding()期间调用finalization,并向其传递IOTAKeyboardServices.AddKeyboardBinding()返回的值(当前未保存)。

请参阅David Hoyle博客中的Chapter 4: Key Bindings and Debugging Tools,该博客提供了使用OpenTools API的键盘绑定向导的示例。

10-08 05:21