[Lazarus] Cross-platform using TRegistry - how to?

Tony Whyman tony.whyman at mccallumwhyman.com
Mon May 4 11:41:27 CEST 2020

I often use TRegistry for cross-platform configuration data and you 
should be able to use it and avoid having to maintain different Linux 
and Windows versions.

Under Linux, you are using TXMLRegistry and this saves registry data in 
an application specific XML file. There can be both a common XML file 
(HKEY_LOCAL_MACHINE) and a per user XML file (HKEY_CURRENT_USER). The 
file's location is always relative to the path returned by 
Sysutils.GetAppConfigDir. I create separate TRegistry instances for 

In the per user case, the filename is $HOME/.config/<vendor 
name>/<application name>/xml.reg, where the vendor and application names 
are set by the callbacks OnGetVendorName (default '') and 
OnGetApplicationName (default exe file name) in Sysutils.

Note that the HKEY_LOCAL_MACHINE xml file is probably in a read only 
location unless you are root.

Otherwise, you just keep the same keynames and values as in Windows 
registry. As reported elsewhere, if you insist on having more than one 
instance of TRegistry (for the same root key) at any one time, you 
cannot assume that the keyname is preserved when switching between 
TRegistry instances, and must (for now) always set the keyname before 
accessing a value.

On 03/05/2020 23:40, Bo Berglund via lazarus wrote:
> I am porting a Windows service application to Linux ARM (RPi4).
> The Windows version is a service and as such its config data resides
> in the Registry below HKLM.
> The Linux version will be a Daemon and I would like as much of the
> code stay unaltered to avoid conversion bugs.
> Now I have read that the FPC TRegistry class is able to use the
> original commands for reading/writing the data by instead using some
> form of ini- or xml-file store on UNIX.
> The existing system written in Delphi2007 uses the following key
> structure:
> HKLM\SOFTWARE\Companyname\Applicationname\Server\(named values)
> HKLM\SOFTWARE\Companyname\Applicationname\Configuration\(named values)
> But how does this work and where/how are the data actually stored in a
> Linux file system?
> I have tried to google this but my search skills are not good enough
> so I came up empty-handed....
> Any insight on this very much appreciated.

More information about the lazarus mailing list