1
votes

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?

1
No I haven't, but I know about that method, and I'm trying to implement the Action Manager's built-in capabilities. - Jerry Dodge
The designer won't let me add action lists or action managers to a data module. This is an XY question. You don't actually care about using data modules. Your problem is other than that. - David Heffernan
@Jerry OK, I understand now. I added what I feel to be a better answer to that question! - David Heffernan
@Jerry You really should try to make the question about your underlying problem. I think that your real problem is that you want have an action manager that is shared between different forms/controls in your app. Ask about that. Data modules may or may not be the solution. You are asking about your solution rather than asking about the problem. - David Heffernan

1 Answers

5
votes

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;
  .....
  .....