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 distinctCaption
values. But you don't have to have separateOnExecute
event handlers. The event handler will receive a reference to the action in itsSender
parameter. Use the sender'sTag
property to refer to a list where your file names are kept. (Don't use theCaption
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.I use code as follows, but you may need to knock it around some. The only thing very obviously missing is
IAbbreviatedFileName
which essentially wraps up the Windows API functionPathCompactPath
. You'll want some way to abbreviate very long file names and that's my preferred choice. Sorry for such a huge dump of code, but somebody may find something of use within!