Re: save registry keys : what's wrong with this code?
[ Delphi
Tutorial ]
Posted by hamed kamely on August 17, 2003 at 12:38:50:
In Reply to: Re: save registry keys : what's wrong with this code? posted by webmaster Guido on December 02, 2002 at 21:06:02:
: : I am trying to save a registry key with all subkeys and values to a file. The file is created but it is empty. I use D5 Enterprise and NT4. : : Thank you. : : procedure TForm1.Button1Click(Sender: TObject); : : const : : sFileName:string = 'c:\temp\_regsaveok'; : : sRegString:string= '\Software\ABBYY'; : : var : : Form1: TForm1; : : Registry1:TRegistry; : : begin : : // delete file if it exists (SaveKey will NOT work if file exists !!!) : : if FileExists(sFilename) then deletefile (sFilename); : : Registry1 := TRegistry.create; : : With Registry1 do begin : : RootKey:= HKEY_LOCAL_MACHINE; : : if SaveKey(sRegString,sFilename) = false then showmessage ('NOT ok'); : : free; : : end; : : end; : ---------------------- : 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 gives 8 KB : HKEY_LOCAL_MACHINE\Software\MicroSoft gives over 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.
Related Articles and Replies:
[ Delphi
Forum ] [ DelphiLand: free Delphi source code, tips, tutorials ]
|