Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write a value into a created Registry in Delphi

Tags:

delphi

   myReg:=TRegistry.Create;
myReg.CreateKey('\sunandan123\');
//myReg.WriteString('Tile','1');
myReg.WriteString ('TileWallpaper','1') ;

This code gives an exception that i 'failed to set the value for 'TileWallpaper'. how to correct it?

Thanks

like image 899
CyprUS Avatar asked Nov 30 '22 08:11

CyprUS


1 Answers

I always do it like this.

procedure TForm1.Button1Click(Sender: TObject);
var R: TRegistry;
begin
  R := TRegistry.Create;
  try
    if not R.OpenKey('Software\CompanyName\ProductName\SubKey', True) then
      RaiseLastOSError;
    R.WriteString('ValueName', '1');
    R.WriteString('Other Value Name', 'Some other value');
  finally R.Free;
  end;
end;
like image 172
Cosmin Prund Avatar answered Jan 07 '23 21:01

Cosmin Prund