Question

In Delphi XE2, I have a Data Module in my Application, and an Action Manager inside that Data Module. I've assigned Keyboard Shortcuts to each action, but when I try to use these shortcuts in the app, it does not catch them.

I'm creating the data module inside the application's initialization (which is moved to a different unit due to IDE distorting code in the project's main file)...

unit AppInit;

interface

uses
  Vcl.Forms,
  Vcl.Themes,
  Vcl.Styles,
  uMain,
  uDataModule
  ;

procedure RunApp;

implementation

procedure RunApp;
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.Title := 'My App';
  TStyleManager.TrySetStyle('Carbon');
  DM:= TDM.Create(nil);
  try
    Application.CreateForm(TfrmMain, frmMain);
    Application.Run;
  finally
    DM.Free;
  end;
end;

end.

The reason for creating the Data Module like this is so all the various forms of the application are able to use the components within it, specifically the Action Manager. It has to be created before the main form is created.

How can I make the keyboard shortcuts of action items work when the action manager is in a data module?

Was it helpful?

Solution

TDataModule is not a descendant of TCustomForm, but rather of TComponent. So a data module does not have a window handle to receive messages, and has no handling for shortcuts like TCustomForm.

function TCustomForm.IsShortCut(var Message: TWMKey): Boolean;

  function DispatchShortCut(const Owner: TComponent) : Boolean;
  .....
  .....
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top