Lazarus

Programming => Operating Systems => Linux => Topic started by: tenox on June 07, 2018, 02:39:34 am

Title: TRegistry on Linux
Post by: tenox on June 07, 2018, 02:39:34 am
This has been previously answered, TRegistry is multi platform and on Linux is supposed to use reg.xml file inside .config/appname/ folder.

Unfortunately this doesn't work for me for some reason. Doing strace I do see that the file is being checked:
access("/home/as/.config/test/reg.xml", F_OK) = -1 ENOENT (No such file or directory)

However it's never created and creating it by hand with touch does nothing, the file never gets written to.

Am I doing something wrong in the code?

Code: Pascal  [Select][+][-]
  1.   Cfg := TRegistry.Create(KEY_READ Or KEY_WRITE);
  2.   Cfg.RootKey := HKEY_CURRENT_USER;
  3.   if Cfg.OpenKey('Software\\Tenox\\test\\',True) then
  4.   begin
  5.      Cfg.WriteBool('TestVal', "foo");
  6.   end
  7.  
Title: Re: TRegistry on Linux
Post by: Handoko on June 07, 2018, 04:37:19 am
Hello tenox,
Welcome to the forum.

This code works on my test on my Linux computer:
(I really saw the reg.xml was created)

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SaveRegistry(Sender: TObject);
  2. var
  3.   Cfg: TRegistry;
  4. begin
  5.   Cfg := TRegistry.Create(KEY_READ Or KEY_WRITE);
  6.   Cfg.RootKey := HKEY_CURRENT_USER;
  7.   if Cfg.OpenKey('Software\\Tenox\test\\',True) then
  8.   begin
  9.      Cfg.WriteString('TestVal', 'foo');
  10.   end;
  11.   Cfg.Free;
  12. end;
Title: Re: TRegistry on Linux
Post by: marcov on June 07, 2018, 10:17:47 am
(why all the double backslashes?)

As you can see handoko frees the class which might be the trigger to write. You can also do cfg.flush; to force a write without closing.
Title: Re: TRegistry on Linux
Post by: tenox on June 08, 2018, 12:37:54 am
Thank you. There is no flush method on this but free worked. Thanks for help!
TinyPortal © 2005-2018