Recent

Author Topic: TRegistry on Linux  (Read 3274 times)

tenox

  • Newbie
  • Posts: 2
TRegistry on Linux
« 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.  

Handoko

  • Hero Member
  • *****
  • Posts: 5132
  • My goal: build my own game engine using Lazarus
Re: TRegistry on Linux
« Reply #1 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;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11384
  • FPC developer.
Re: TRegistry on Linux
« Reply #2 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.
« Last Edit: June 07, 2018, 10:19:28 am by marcov »

tenox

  • Newbie
  • Posts: 2
Re: TRegistry on Linux
« Reply #3 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