Posted by webmaster Guido on December 02, 2002 In Reply to: save registry keys : what's wrong with this code? posted by P12160 Stefan Loeners on November 28, 2002:
: I am trying to save a registry key in Delphi, with all subkeys and values to a file.
The file is created but it is empty. I use Delphi 5 Enterprise and NT4. : procedure TForm1.Button1Click(Sender: TObject); Just tested SaveKey() on a Windows 98 system and it works fine. Here's an exact copy of the code, copied-and-pasted straight from Delphi's editor: procedure TForm1.Button1Click(Sender: TObject); const sFileName = 'c:\temp\test'; sRegString = 'Software\Borland\Delphi'; var Reg: TRegistry; begin if FileExists(sFilename) then begin FileSetAttr(sFilename, 0); // clear Read-Only and Hidden flags Deletefile(sFilename); end; Reg := TRegistry.Create; try Reg.RootKey:= HKEY_LOCAL_MACHINE; if Reg.SaveKey(sRegString, sFilename) then Showmessage('Saved: ' + sFilename) else Showmessage('NOT saved'); finally Reg.Free; end; end;
|
|
Sorry, I really have no clue about what could be wrong in your case. Here are some loose ideas:
- I had no NT system available right now, but I suppose that NT is not the cause of your problems. Anyway, to be sure, you could try the code on a Win95/98/ME or XP system to see if there is a difference.
- The saved file is a read-only, hidden *binary* file, so it might seem empty when opened with a text-editor. You could check its contents with a hex-viewer. Or maybe save various items, some small and some big, and check that the filesizes are different:
HKEY_LOCAL_MACHINE\Software\Borland\Delphi = 8 KB
HKEY_LOCAL_MACHINE\Software\MicroSoft > 1.5 MB ;)
- On the Win98 system, SaveKey truncates the filename to 8 characters, e.g. _regsaveok becomes _regsave. Don't know if this happens also with NT4, but make sure anyway that you are looking at the right file.