home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 April / PCWorld_2000-04_cd.bin / Komunik / Servery / PinkNet / pnws1076prof.exe / file0140.bin < prev    next >
Encoding:
Text File  |  2000-03-12  |  1.6 KB  |  58 lines

  1. unit NTRegistry;
  2. {*******************************************************************************
  3.  
  4. Author:       HrbßΦ David
  5. Email:        hrbac.david@usa.net, david@slovesa.hypermart.net
  6. Creation:     18th March 1999
  7. Version:      1.0
  8. Object:       TNTRegistry
  9. Legal issues: Copyright ⌐ 1994-1999 by David HrbßΦ <hrbac.david@usa.net>
  10.  
  11. 18th Mar 1999 1st release, TNTReg object
  12. 22nd Mar 1999 Changed to TNTRegistry
  13. *******************************************************************************}
  14.  
  15. interface
  16.  
  17. uses
  18.   Windows, Registry;
  19.  
  20. type
  21.   TNTRegistry = class(TRegistry)
  22.   private
  23.   public
  24.     function OpenKey(const Key: string; CanCreate: Boolean): Boolean;
  25.   end;
  26.  
  27. implementation
  28.  
  29. function IsRelative(const Value: string): Boolean;
  30. begin
  31.   Result := not ((Value <> '') and (Value[1] = '\'));
  32. end;
  33.  
  34. function TNTRegistry.OpenKey(const Key: string; CanCreate: Boolean): Boolean;
  35. var
  36.   TempKey: HKey;
  37.   S: string;
  38.   Disposition: Integer;
  39.   Relative: Boolean;
  40. begin
  41.   S := Key;
  42.   Relative := IsRelative(S);
  43.   if not Relative then Delete(S, 1, 1);
  44.   TempKey := 0;
  45.   if not CanCreate or (S = '') then
  46.   begin
  47.     Result := RegOpenKeyEx(GetBaseKey(Relative), PChar(S), 0,KEY_READ or KEY_WRITE, TempKey) = ERROR_SUCCESS;
  48.   end else
  49.     Result := RegCreateKeyEx(GetBaseKey(Relative), PChar(S), 0, nil,REG_OPTION_NON_VOLATILE, KEY_READ or KEY_WRITE, nil, TempKey, @Disposition) = ERROR_SUCCESS;
  50.   if Result then
  51.   begin
  52.     if (CurrentKey <> 0) and Relative then
  53.     S := CurrentPath + '\' + S;
  54.     ChangeKey(TempKey, S);
  55.   end;
  56. end;
  57.  
  58. end.