TAction.ShortCut not working in dynamically created TAction
delphi, delphi-xe5, ribbon, shortcut
Solution
When you create a new action its ActionList property is not automatically set to the Owner you provide with Create. You have to set ActionList explicitely to make it work.
newAction := TAction.Create(MainForm.ActionManager);
newAction.ActionList := MainForm.ActionManager;
newAction.Name := 'Topics';
Problem
In Delphi XE5: I have a TActionManager (called ActionManager) and a TRibbon (called Ribbon) on my form. I am adding a custom action like this: ``` 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'); ``` After this I place them on a ribbon in a page/tab and in a group: ``` 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; ``` The action works fine when I click it, However when I press 'F1' nothing happens. When I add the action manually using the Delphi editors the shortcuts work fine. I already tried: newMenu.ShortCut := newAction.ShortCut This doesn't help. What am I missing?