1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Books|Link Back

Most Recently Used (MRU) menu component - TadpMRU
Full source code of a TadpMRU component, a non-visual component which simplifies implementing a "Most Recently Used" file list in a menu (or a popup menu). The TadpMRU component allows for quick selection of a file that was recently accessed (opened) in an application.
Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
More of this Feature
Download FULL source
Join the Discussion
"Post your views, comments, questions and doubts to this article."
Related Resources
Building Delphi components - tutorials
Free source Delphi components

MRU - Most Recently Used
Many applications offer a list of most recently used files (like Delphi's File | Reopen menu) - a list that reflects the user's most recently accessed files in an application.
The MRU list allows for quick selection of a file that was recently opened without having to select an Open menu item and search to locate a specific lately accessed file.

Delphi does *not* provide any built-in mechanism for managing a MRU list.
Note: ActionBands provide built-in storage making MRU menus very easy to implement - Delphi 6 and later ship with a demo examples that show how you can easily set up an MRU history list for recently opened files

The TadpMRU Delphi component is a non-visual component which simplifies implementing a "Most Recently Used" file list in a menu (or a popup menu). Here are the TadpMRU component's features:
  • MRU menu items are attached to a "ParentMenuItem"
  • Dynamic, supports *unlimited* number of MRU items.
  • A maximum number of MRU entries can be defined.
  • Files can be added or removed from the list.
  • The files are listed with the most recently used at the top of the list (from the "most recent" to "least recent.")
  • Each file can be displayed using the full path name or just the file name.
  • The MRU list is saved to the Registry upon application termination and loaded upon application startup.
  • Enables more Registry storage areas by providing the RegistryPath property
  • Exposes an OnClick event with the Filename as a parameter.
  • and more...

Here's a list of public and published properties and methods:

procedure AddItem(const FileName: string);
Adds the Filename to the MRU list, as the first item.

function RemoveItem(const FileName : string) : boolean;
Removes a MRU item provided with a file name. Returns true if an existing item was removed; false otherwise.

TadpMRU in Object InspectorMaxItems: Cardinal
Gets or sets the maximum number of files in the MRU list.

ShowFullPath : boolean
Gets or sets the value that indicates whether files as menu items are displayed with full file name (or just using the file name).

RegistryPath : string
Gets or sets the string value representing the key in Registry where MRU entries are saved. If omitted the MRU list is NOT saved upon application termination. The root key used is HKEY_CURRENT_USER.

ParentMenuItem : TMenuItem
Determines the menu item that the MRU items will be added to as child menu items.

OnClick: TMRUClickEvent; TMRUClickEvent = procedure(Sender: TObject; const FileName: String) of object;
Triggered when a "MRU menu item" is clicked.

Installing into a Component palette
First, download the component. The TadpMRU comes as a single unit file (.pas extension). You'll need to add the component into an existing package. Here's "How to Install Custom Component in Delphi (into Existing Package)"

TadpMRU - example application
Here's a sample example of using the TadpMRU Delphi component:

TadpMRU at design time

and at run-time:

TadpMRU at run time

That's it. Don't forget to download the component; and as always if there are any questions or comments please post them on the Delphi Programming Forum.

~ Zarko Gajic

All graphics (if any) in this feature created by Zarko Gajic.

More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by: DATE or by TOPIC.
Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter

Got some code to share? Got a question? Need some help?

©2016 About.com. All rights reserved.