I have an TActionManager, and a TActionMainMenuBar, and I know how to add an TActionClientItem for each MRU file to the main menu bar. But do I have to create a separate action for each MRU file in the list? Or is there a way to create just one action, and somehow pass a tag or something to the action's OnExecute event based on which MRU file was clicked?
Delphi's help says: "For more information about MRU lists, sample code, and methods for finding actions in lists, see FindItemByAction and FindItemByCaption in the online Help." But I can't find anything in those subjects that is helpful, and certainly not sample code. I'd really like to avoid using a 3rd party component to get this done.
You'll have a separate TAction
for each menu item anyway so that they can have distinct Caption
values. But you don't have to have separate OnExecute
event handlers. The event handler will receive a reference to the action in its Sender
parameter. Use the sender's Tag
property to refer to a list where your file names are kept. (Don't use the Caption
property to discover which file to open; that restricts you from doing nice things like adding accelerators or abbreviating unwieldy paths.)
That's what the documentation assumes you'd do, too. FindItemByAction
returns the first item that the given action is attached to. If you attach a single action to all your MRU menu items, then you won't be able to use that function to tell you which menu was selected. On the other hand, the menu item wouldn't hold any more information than the associated action would, so I see no reason to look for the menu item anyway. Just use the information from the action directly.