Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delphi12+Win10 run error : Range check error #8

Open
zystudios opened this issue Mar 6, 2024 · 0 comments
Open

Delphi12+Win10 run error : Range check error #8

zystudios opened this issue Mar 6, 2024 · 0 comments

Comments

@zystudios
Copy link

I'm using Delphi 12 right now, and I just created a new vcl project and pasted the code from the demo, and when I click on run, it reports an error : Range check error

I don't know why. It's strange.

I had no problems with Delphi 10 before, is it a Delphi 12 bug?

1
2
1111

The code is very simple. copy from demo

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Threading, Vcl.StdCtrls, Vcl.ExtCtrls,

  Winapi.Hooks;

type
  TFormMain = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    FHook: THook;
  public
    { Public declarations }
  end;

var
  FormMain: TFormMain;

implementation

{$R *.dfm}

procedure TFormMain.Button1Click(Sender: TObject);
const
  Captions: array [Boolean] of string = ('Decativate', 'Active');
begin
  FHook.Active := not FHook.Active;
  Button1.Caption := Captions[not FHook.Active];
end;



procedure TFormMain.FormCreate(Sender: TObject);
begin
  FHook := THookInstance<TLowLevelKeyboardHook>.CreateHook(Self);
  FHook.OnPreExecute := procedure(Hook: THook; var HookMsg: THookMessage)
    var
      LLKeyBoardHook: TLowLevelKeyboardHook;
      ScanCode: integer;
    begin
      LLKeyBoardHook := TLowLevelKeyboardHook(Hook);
      if LLKeyBoardHook.LowLevelKeyStates.KeyState <> ksKeyDown then
        exit;

      ScanCode := LLKeyBoardHook.KeyName.ScanCode;

      if not(ScanCode in [VK_NUMPAD0 .. VK_NUMPAD9, VK_0 .. VK_9]) then
      begin
        Caption := 'Got ya! Key [' + LLKeyBoardHook.KeyName.KeyExtName + '] blocked.';
        HookMsg.Result := 1;
      end
      else
        Caption := '';
    end;
end;

end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant