Access Registry

To access registry, you should add Registry in your USES clause. Then remember to specify False in OpenKey() method to read values, and True to write values. So simple, isn't it??

Here is the sample source code:

 
procedure ReadRegistry;
var
  regEntry : TRegistry;
begin
  // Create an instance of TRegistry
  regEntry := TRegistry.Create;
  try
    regEntry.RootKey := HKEY_CURRENT_USER;
    try
      if regEntry.OpenKey( 'Software\Hianoto', False ) then begin
        nInteger := regEntry.ReadInteger( 'Integer' );
        regEntry.CloseKey;
      end;
    except
      // Error Handler
    end;
  finally
    // Destroy the instance
    regEntry.Free;
  end;
end;
 
procedure WriteRegistry;
var
  regEntry : TRegistry;
begin
  // Create an instance of TRegistry
  regEntry := TRegistry.Create;
  try
    regEntry.RootKey := HKEY_CURRENT_USER;
    try
      if regEntry.OpenKey( 'Software\Hianoto', True ) then begin
        regEntry.WriteInteger( 'Integer', 1 );
        regEntry.WriteString( 'String', 'Hian' );
        regEntry.CloseKey;
      end;
    except
      // Error Handler
    end;
  finally
    regEntry.Free;
  end;
end;