Search code examples
delphihotkeysdelphi-10.4-sydney

Why does THotKey not have an Align property and how can I add it?


In a Delphi 10.4.2 32-bit VCL Application in Windows 10, I tried to use a THotKey control to enter hotkeys. Since I use the Align property a lot to create a neat UI, I wondered why THotKey does not have an Align property. Even TRzHotKeyEdit, TJvHotKey, and TJvDotNetHotKey do not have an Align property.

Is it possible to simulate a THotkey.Align property? Or is there another HotKey control with an Align property?


Solution

  • Create a unit to use it as a new component derived from THotKey:

    unit ExtHotKey;
    
    // Published the Align property
    
    interface
    
    uses
      System.Classes,
      Vcl.ComCtrls;
    
    type
      TExtHotKey = class(THotKey)
      published
        property Align;
      end;
    
    procedure Register;
    
    implementation
    
    procedure Register;
    begin
      System.Classes.RegisterComponents('PAComponents', [TExtHotKey]);
    end;
    
    end.
    

    Then insert it into a new or existing package and install the package.

    After that, the Align property is available in the Object Inspector and it works perfectly:

    enter image description here