Delphi – What are the best practices for storing user preferences and settings in Win32 Delphi applications

delphidelphi-2010preferencessettings

I want to store user preferences (colors,toolbars on/off, panel widths in pixels) and application settings (last 10 files, default save directory, default open directory) within my Delphi Win32 application. What is the best practice for doing this?

Best Answer

You have two main options:

  1. Store the settings in a file under the user profile. If your settings are simple enough then INI files work perfectly adequately.
  2. Store the settings in the registry, under HKEY_CURRENT_USER which is also part of the profile.

Personally I prefer to use the registry since it provides hierarchical storage for free. If you use a file, then you have to do that yourself which can be a bind for more complex data.

On the other hand, if you want to write a portable app, i.e. one that can live on a memory stick, then a user settings file that sits alongside the executable is the way to go.