Delphi Tutorials »

Registry as Delphi INI-File -- part 1


Better use Delphi's TRegistryIniFile instead of TRegIniFile, it has more possibilities and it's more compatible with TIniFile.

Also, if you switch from INI files to the registry, you can rewrite your application with a minimum of coding changes: only change the code for Create.
TRegistryIniFile interprets the FileName property as a subkey under the registry's root key, HKEY_CURRENT_USER by default. So, instead of:

IniFile := TIniFile.Create('C:\Software\MyApp');

you code it as:

RegistryIniFile := TRegistryIniFile.Create('Software\MyApp');

Most methods are the same as in TIniFile: ReadString, ReadInteger, ReadFloat,..., WriteString, WriteInteger, WriteFloat,..., ReadSection, ReadSections, DeleteKey, EraseSection, and so on... Don't worry about what happens behind the scenes: sections are treated as sub- keys in the registry, and data entries under a section are treated as ident/data value pairs of that sub-key.
For example, the following code writes an ident/value pair in the key HKEY_CURRENT_USER\Software\MyApp\Images:

  RIniFile: TRegistryIniFile;
  RIniFile := TRegistryIniFile.Create('Software\MyApp');
  RIniFile.WriteString('Images', C:\Pics\Latest\bird.tif', 
   'Original image as shot from camera');

The key is created automatically if it doesn't exist already, otherwise you overwrite the existing value(s).

Part 2: Registry as Delphi INI-File -- part 2 »


TOP   DelphiLand Club  DC Library  Forum  Forum Archives
Crash Course Delphi  Tips  Source Code  Downloads  Links

© Copyright 1999-2018 
Studiebureau Festraets