Jump to content


Photo

SaveToRegistry question


  • Please log in to reply
4 replies to this topic

#1 Jordan

Jordan
  • Members
  • 14 posts

Posted 13 July 2009 - 08:29 PM

How can I specify the registry root (HKEY_LOCAL_MACHINE, for example) that will be used in the SaveToRegistry method? It seems that this method uses HKEY_CURRENT_USER by default.

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 13 July 2009 - 09:13 PM

Hello Jordan,

Unfortunatelly, TRegistryIniFile which is used for saving settings into registry, set values under tha HKEY_CURRENT_USER root key. Maybe is there a way to change this, but I am not sure how sad.gif

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Jordan

Jordan
  • Members
  • 14 posts

Posted 13 July 2009 - 10:38 PM

Delphi provides a RootKey property in the TRegInitFile. You can set it immediately after the Create. You would need to have a second optional parameter in the call to SaveToRegistry to allow a non-default key to be specified. This line of code should work:

IniFile.RegIniFile.RootKey := HKEY_LOCAL_MACHINE;



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 14 July 2009 - 08:40 AM

Thank you Jordan,

I will test it now, and add it into official release.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,289 posts
  • Gender:Male

Posted 14 July 2009 - 06:32 PM

Hello Jordan,

Here is a new code:

CODE
  TNxCustomGridControl = class(TNxScrollControl)
.
.
.
    procedure SaveToRegistry(const KeyName: WideString; ID: string = ''; RootKey: HKEY = HKEY_CURRENT_USER);
.
.
.
procedure TNxCustomGridControl.SaveToRegistry(const KeyName: WideString;
  ID: string; RootKey: HKEY);
var
  IniFile: TRegistryIniFile;
begin
  try
    IniFile := TRegistryIniFile.Create(KeyName);
    IniFile.RegIniFile.RootKey := RootKey;
    SaveToIniFile(KeyName, IniFile, ID);
  finally
    FreeAndNil(IniFile);
  end;
end;


Thank you for your code tip. I hope that now it works as expected.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users