当Action Manager在数据模块中时,未捕获键盘快捷键?

Jer*_*dge 1 delphi keyboard-shortcuts datamodule delphi-xe2 tactionmanager

在Delphi XE2中,我的应用程序中有一个数据模块,数据模块中有一个Action Manager.我已经为每个操作分配了键盘快捷键,但是当我尝试在应用程序中使用这些快捷键时,它并没有捕获它们.

我正在应用程序的初始化中创建数据模块(由于IDE扭曲了项目主文件中的代码,它被移动到另一个单元)...

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.
Run Code Online (Sandbox Code Playgroud)

创建这样的数据模块的原因是,所有各种形式的应用程序都能够使用其中的组件,特别是Action Manager.必须在创建主窗体之前创建它.

当操作管理器位于数据模块中时,如何使操作项的键盘快捷键起作用?

bum*_*mmi 5

TDataModule不是TCustomForm,而是... 的后代TComponent.因此,数据模块没有窗口句柄来接收消息,并且没有处理快捷方式,例如TCustomForm.

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

  function DispatchShortCut(const Owner: TComponent) : Boolean;
  .....
  .....
Run Code Online (Sandbox Code Playgroud)