TAction.ShortCut 在动态创建的 TAction 中不起作用

mrC*_*ass 3 delphi ribbon shortcut delphi-xe5

在Delphi XE5中:我的窗体上有一个TActionManager(称为ActionManager)和一个TRibbon(称为Ribbon)。我正在添加这样的自定义操作:

ActionBar := ActionManager.ActionBars.Add;
newAction := TAction.Create(MainForm.ActionManager);
newAction.Name := 'Topics';
newAction.Caption := 'Topics';
newAction.OnExecute := MainForm.HelpTopicsItemClick;
newMenu := ActionBar.Items.Add;
newMenu.Action := newAction;
newAction.ShortCut := TextToShortCut('F1');
Run Code Online (Sandbox Code Playgroud)

之后,我将它们放在页面/选项卡和组中的功能区上:

rp := TRibbonPage.Create(ActionManager);
rp.Parent := Ribbon;
Ribbon.AddTab(rp).Caption := 'Help';
rg := TRibbonGroup.Create(ActionManager);
rg.Parent := rp;
rg.ActionManager := ActionManager;
rg.Caption := 'Help';
rg.ActionClient := ActionBar;
Run Code Online (Sandbox Code Playgroud)

当我单击它时,该操作工作正常,但是当我按“F1”时,什么也没有发生。当我使用 Delphi 编辑器手动添加操作时,快捷方式工作正常。

我已经尝试过: newMenu.ShortCut := newAction.ShortCut

这没有帮助。我缺少什么?

Uwe*_*abe 5

当您创建新操作时,其 ActionList 属性不会自动设置为您通过 Create 提供的 Owner。您必须显式设置 ActionList 才能使其工作。

newAction := TAction.Create(MainForm.ActionManager);
newAction.ActionList := MainForm.ActionManager;
newAction.Name := 'Topics';
Run Code Online (Sandbox Code Playgroud)