home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Vcl / registry.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  36KB  |  1,361 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Borland Delphi Visual Component Library         }
  5. {                                                       }
  6. {       Copyright (c) 1995,99 Inprise Corporation       }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit Registry;
  11.  
  12. {$R-,T-,H+,X+}
  13.  
  14. interface
  15.  
  16. uses Windows, Classes, SysUtils, IniFiles;
  17.  
  18. type
  19.   ERegistryException = class(Exception);
  20.  
  21.   TRegKeyInfo = record
  22.     NumSubKeys: Integer;
  23.     MaxSubKeyLen: Integer;
  24.     NumValues: Integer;
  25.     MaxValueLen: Integer;
  26.     MaxDataLen: Integer;
  27.     FileTime: TFileTime;
  28.   end;
  29.  
  30.   TRegDataType = (rdUnknown, rdString, rdExpandString, rdInteger, rdBinary);
  31.  
  32.   TRegDataInfo = record
  33.     RegData: TRegDataType;
  34.     DataSize: Integer;
  35.   end;
  36.  
  37.   TRegistry = class(TObject)
  38.   private
  39.     FCurrentKey: HKEY;
  40.     FRootKey: HKEY;
  41.     FLazyWrite: Boolean;
  42.     FCurrentPath: string;
  43.     FCloseRootKey: Boolean;
  44.     FAccess: LongWord;
  45.     procedure SetRootKey(Value: HKEY);
  46.   protected
  47.     procedure ChangeKey(Value: HKey; const Path: string);
  48.     function GetBaseKey(Relative: Boolean): HKey;
  49.     function GetData(const Name: string; Buffer: Pointer;
  50.       BufSize: Integer; var RegData: TRegDataType): Integer;
  51.     function GetKey(const Key: string): HKEY;
  52.     procedure PutData(const Name: string; Buffer: Pointer; BufSize: Integer; RegData: TRegDataType);
  53.     procedure SetCurrentKey(Value: HKEY);
  54.   public
  55.     constructor Create; overload;
  56.     constructor Create(AAccess: LongWord); overload;
  57.     destructor Destroy; override;
  58.     procedure CloseKey;
  59.     function CreateKey(const Key: string): Boolean;
  60.     function DeleteKey(const Key: string): Boolean;
  61.     function DeleteValue(const Name: string): Boolean;
  62.     function GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
  63.     function GetDataSize(const ValueName: string): Integer;
  64.     function GetDataType(const ValueName: string): TRegDataType;
  65.     function GetKeyInfo(var Value: TRegKeyInfo): Boolean;
  66.     procedure GetKeyNames(Strings: TStrings);
  67.     procedure GetValueNames(Strings: TStrings);
  68.     function HasSubKeys: Boolean;
  69.     function KeyExists(const Key: string): Boolean;
  70.     function LoadKey(const Key, FileName: string): Boolean;
  71.     procedure MoveKey(const OldName, NewName: string; Delete: Boolean);
  72.     function OpenKey(const Key: string; CanCreate: Boolean): Boolean;
  73.     function OpenKeyReadOnly(const Key: String): Boolean;
  74.     function ReadCurrency(const Name: string): Currency;
  75.     function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
  76.     function ReadBool(const Name: string): Boolean;
  77.     function ReadDate(const Name: string): TDateTime;
  78.     function ReadDateTime(const Name: string): TDateTime;
  79.     function ReadFloat(const Name: string): Double;
  80.     function ReadInteger(const Name: string): Integer;
  81.     function ReadString(const Name: string): string;
  82.     function ReadTime(const Name: string): TDateTime;
  83.     function RegistryConnect(const UNCName: string): Boolean;
  84.     procedure RenameValue(const OldName, NewName: string);
  85.     function ReplaceKey(const Key, FileName, BackUpFileName: string): Boolean;
  86.     function RestoreKey(const Key, FileName: string): Boolean;
  87.     function SaveKey(const Key, FileName: string): Boolean;
  88.     function UnLoadKey(const Key: string): Boolean;
  89.     function ValueExists(const Name: string): Boolean;
  90.     procedure WriteCurrency(const Name: string; Value: Currency);
  91.     procedure WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
  92.     procedure WriteBool(const Name: string; Value: Boolean);
  93.     procedure WriteDate(const Name: string; Value: TDateTime);
  94.     procedure WriteDateTime(const Name: string; Value: TDateTime);
  95.     procedure WriteFloat(const Name: string; Value: Double);
  96.     procedure WriteInteger(const Name: string; Value: Integer);
  97.     procedure WriteString(const Name, Value: string);
  98.     procedure WriteExpandString(const Name, Value: string);
  99.     procedure WriteTime(const Name: string; Value: TDateTime);
  100.     property CurrentKey: HKEY read FCurrentKey;
  101.     property CurrentPath: string read FCurrentPath;
  102.     property LazyWrite: Boolean read FLazyWrite write FLazyWrite;
  103.     property RootKey: HKEY read FRootKey write SetRootKey;
  104.     property Access: LongWord read FAccess write FAccess;
  105.   end;
  106.  
  107.   TRegIniFile = class(TRegistry)
  108.   private
  109.     FFileName: string;
  110.   public
  111.     constructor Create(const FileName: string); overload;
  112.     constructor Create(const FileName: string; AAccess: LongWord); overload;
  113.     function ReadString(const Section, Ident, Default: string): string;
  114.     function ReadInteger(const Section, Ident: string;
  115.       Default: Longint): Longint;
  116.     procedure WriteInteger(const Section, Ident: string; Value: Longint);
  117.     procedure WriteString(const Section, Ident, Value: String);
  118.     function ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
  119.     procedure WriteBool(const Section, Ident: string; Value: Boolean);
  120.     procedure ReadSection(const Section: string; Strings: TStrings);
  121.     procedure ReadSections(Strings: TStrings);
  122.     procedure ReadSectionValues(const Section: string; Strings: TStrings);
  123.     procedure EraseSection(const Section: string);
  124.     procedure DeleteKey(const Section, Ident: String);
  125.     property FileName: string read FFileName;
  126.   end;
  127.  
  128.   TRegistryIniFile = class(TCustomIniFile)
  129.   private
  130.     FRegIniFile: TRegIniFile;
  131.   public
  132.     constructor Create(const FileName: string); overload;
  133.     constructor Create(const FileName: string; AAccess: LongWord); overload;
  134.     destructor Destroy; override;
  135.     function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime; override;
  136.     function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
  137.     function ReadInteger(const Section, Ident: string; Default: Longint): Longint; override;
  138.     function ReadFloat(const Section, Name: string; Default: Double): Double; override;
  139.     function ReadString(const Section, Ident, Default: string): string; override;
  140.     function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime; override;
  141.     procedure WriteDate(const Section, Name: string; Value: TDateTime); override;
  142.     procedure WriteDateTime(const Section, Name: string; Value: TDateTime); override;
  143.     procedure WriteFloat(const Section, Name: string; Value: Double); override;
  144.     procedure WriteInteger(const Section, Ident: string; Value: Longint); override;
  145.     procedure WriteString(const Section, Ident, Value: String); override;
  146.     procedure WriteTime(const Section, Name: string; Value: TDateTime); override;
  147.     procedure ReadSection(const Section: string; Strings: TStrings); override;
  148.     procedure ReadSections(Strings: TStrings); override;
  149.     procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
  150.     procedure EraseSection(const Section: string); override;
  151.     procedure DeleteKey(const Section, Ident: String); override;
  152.     procedure UpdateFile; override;
  153.  
  154.     property RegIniFile: TRegIniFile read FRegIniFile;
  155.   end;
  156.  
  157. implementation
  158.  
  159. uses Consts;
  160.  
  161. procedure ReadError(const Name: string);
  162. begin
  163.   raise ERegistryException.CreateResFmt(@SInvalidRegType, [Name]);
  164. end;
  165.  
  166. function IsRelative(const Value: string): Boolean;
  167. begin
  168.   Result := not ((Value <> '') and (Value[1] = '\'));
  169. end;
  170.  
  171. function RegDataToDataType(Value: TRegDataType): Integer;
  172. begin
  173.   case Value of
  174.     rdString: Result := REG_SZ;
  175.     rdExpandString: Result := REG_EXPAND_SZ;
  176.     rdInteger: Result := REG_DWORD;
  177.     rdBinary: Result := REG_BINARY;
  178.   else
  179.     Result := REG_NONE;
  180.   end;
  181. end;
  182.  
  183. function DataTypeToRegData(Value: Integer): TRegDataType;
  184. begin
  185.   if Value = REG_SZ then Result := rdString
  186.   else if Value = REG_EXPAND_SZ then Result := rdExpandString
  187.   else if Value = REG_DWORD then Result := rdInteger
  188.   else if Value = REG_BINARY then Result := rdBinary
  189.   else Result := rdUnknown;
  190. end;
  191.  
  192. constructor TRegistry.Create;
  193. begin
  194.   RootKey := HKEY_CURRENT_USER;
  195.   FAccess := KEY_ALL_ACCESS;
  196.   LazyWrite := True;
  197. end;
  198.  
  199. constructor TRegistry.Create(AAccess: LongWord);
  200. begin
  201.   Create;
  202.   FAccess := AAccess;
  203. end;
  204.  
  205. destructor TRegistry.Destroy;
  206. begin
  207.   CloseKey;
  208.   inherited;
  209. end;
  210.  
  211. procedure TRegistry.CloseKey;
  212. begin
  213.   if CurrentKey <> 0 then
  214.   begin
  215.     if LazyWrite then
  216.       RegCloseKey(CurrentKey) else
  217.       RegFlushKey(CurrentKey);
  218.     FCurrentKey := 0;
  219.     FCurrentPath := '';
  220.   end;
  221. end;
  222.  
  223. procedure TRegistry.SetRootKey(Value: HKEY);
  224. begin
  225.   if RootKey <> Value then
  226.   begin
  227.     if FCloseRootKey then
  228.     begin
  229.       RegCloseKey(RootKey);
  230.       FCloseRootKey := False;
  231.     end;
  232.     FRootKey := Value;
  233.     CloseKey;
  234.   end;
  235. end;
  236.  
  237. procedure TRegistry.ChangeKey(Value: HKey; const Path: string);
  238. begin
  239.   CloseKey;
  240.   FCurrentKey := Value;
  241.   FCurrentPath := Path;
  242. end;
  243.  
  244. function TRegistry.GetBaseKey(Relative: Boolean): HKey;
  245. begin
  246.   if (CurrentKey = 0) or not Relative then
  247.     Result := RootKey else
  248.     Result := CurrentKey;
  249. end;
  250.  
  251. procedure TRegistry.SetCurrentKey(Value: HKEY);
  252. begin
  253.   FCurrentKey := Value;
  254. end;
  255.  
  256. function TRegistry.CreateKey(const Key: string): Boolean;
  257. var
  258.   TempKey: HKey;
  259.   S: string;
  260.   Disposition: Integer;
  261.   Relative: Boolean;
  262. begin
  263.   TempKey := 0;
  264.   S := Key;
  265.   Relative := IsRelative(S);
  266.   if not Relative then Delete(S, 1, 1);
  267.   Result := RegCreateKeyEx(GetBaseKey(Relative), PChar(S), 0, nil,
  268.     REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, TempKey, @Disposition) = ERROR_SUCCESS;
  269.   if Result then RegCloseKey(TempKey)
  270.   else raise ERegistryException.CreateResFmt(@SRegCreateFailed, [Key]);
  271. end;
  272.  
  273. function TRegistry.OpenKey(const Key: String; Cancreate: boolean): Boolean;
  274. var
  275.   TempKey: HKey;
  276.   S: string;
  277.   Disposition: Integer;
  278.   Relative: Boolean;
  279. begin
  280.   S := Key;
  281.   Relative := IsRelative(S);
  282.  
  283.   if not Relative then Delete(S, 1, 1);
  284.   TempKey := 0;
  285.   if not CanCreate or (S = '') then
  286.   begin
  287.     Result := RegOpenKeyEx(GetBaseKey(Relative), PChar(S), 0,
  288.       FAccess, TempKey) = ERROR_SUCCESS;
  289.   end else
  290.     Result := RegCreateKeyEx(GetBaseKey(Relative), PChar(S), 0, nil,
  291.       REG_OPTION_NON_VOLATILE, FAccess, nil, TempKey, @Disposition) = ERROR_SUCCESS;
  292.   if Result then
  293.   begin
  294.     if (CurrentKey <> 0) and Relative then S := CurrentPath + '\' + S;
  295.     ChangeKey(TempKey, S);
  296.   end;
  297. end;
  298.  
  299. function TRegistry.OpenKeyReadOnly(const Key: String): Boolean;
  300. var
  301.   TempKey: HKey;
  302.   S: string;
  303.   Relative: Boolean;
  304. begin
  305.   S := Key;
  306.   Relative := IsRelative(S);
  307.  
  308.   if not Relative then Delete(S, 1, 1);
  309.   TempKey := 0;
  310.   Result := RegOpenKeyEx(GetBaseKey(Relative), PChar(S), 0,
  311.       KEY_READ, TempKey) = ERROR_SUCCESS;
  312.   if Result then
  313.   begin
  314.     FAccess := KEY_READ;
  315.     if (CurrentKey <> 0) and Relative then S := CurrentPath + '\' + S;
  316.     ChangeKey(TempKey, S);
  317.   end;
  318. end;
  319.  
  320. function TRegistry.DeleteKey(const Key: string): Boolean;
  321. var
  322.   Len: DWORD;
  323.   I: Integer;
  324.   Relative: Boolean;
  325.   S, KeyName: string;
  326.   OldKey, DeleteKey: HKEY;
  327.   Info: TRegKeyInfo;
  328. begin
  329.   S := Key;
  330.   Relative := IsRelative(S);
  331.   if not Relative then Delete(S, 1, 1);
  332.   OldKey := CurrentKey;
  333.   DeleteKey := GetKey(Key);
  334.   if DeleteKey <> 0 then
  335.   try
  336.     SetCurrentKey(DeleteKey);
  337.     if GetKeyInfo(Info) then
  338.     begin
  339.       SetString(KeyName, nil, Info.MaxSubKeyLen + 1);
  340.       for I := Info.NumSubKeys - 1 downto 0 do
  341.       begin
  342.         Len := Info.MaxSubKeyLen + 1;
  343.         if RegEnumKeyEx(DeleteKey, DWORD(I), PChar(KeyName), Len, nil, nil, nil,
  344.           nil) = ERROR_SUCCESS then
  345.           Self.DeleteKey(PChar(KeyName));
  346.       end;
  347.     end;
  348.   finally
  349.     SetCurrentKey(OldKey);
  350.     RegCloseKey(DeleteKey);
  351.   end;
  352.   Result := RegDeleteKey(GetBaseKey(Relative), PChar(S)) = ERROR_SUCCESS;
  353. end;
  354.  
  355. function TRegistry.DeleteValue(const Name: string): Boolean;
  356. begin
  357.   Result := RegDeleteValue(CurrentKey, PChar(Name)) = ERROR_SUCCESS;
  358. end;
  359.  
  360. function TRegistry.GetKeyInfo(var Value: TRegKeyInfo): Boolean;
  361. begin
  362.   FillChar(Value, SizeOf(TRegKeyInfo), 0);
  363.   Result := RegQueryInfoKey(CurrentKey, nil, nil, nil, @Value.NumSubKeys,
  364.     @Value.MaxSubKeyLen, nil, @Value.NumValues, @Value.MaxValueLen,
  365.     @Value.MaxDataLen, nil, @Value.FileTime) = ERROR_SUCCESS;
  366.   if SysLocale.FarEast and (Win32Platform = VER_PLATFORM_WIN32_NT) then
  367.     with Value do
  368.     begin
  369.       Inc(MaxSubKeyLen, MaxSubKeyLen);
  370.       Inc(MaxValueLen, MaxValueLen);
  371.     end;
  372. end;
  373.  
  374. procedure TRegistry.GetKeyNames(Strings: TStrings);
  375. var
  376.   Len: DWORD;
  377.   I: Integer;
  378.   Info: TRegKeyInfo;
  379.   S: string;
  380. begin
  381.   Strings.Clear;
  382.   if GetKeyInfo(Info) then
  383.   begin
  384.     SetString(S, nil, Info.MaxSubKeyLen + 1);
  385.     for I := 0 to Info.NumSubKeys - 1 do
  386.     begin
  387.       Len := Info.MaxSubKeyLen + 1;
  388.       RegEnumKeyEx(CurrentKey, I, PChar(S), Len, nil, nil, nil, nil);
  389.       Strings.Add(PChar(S));
  390.     end;
  391.   end;
  392. end;
  393.  
  394. procedure TRegistry.GetValueNames(Strings: TStrings);
  395. var
  396.   Len: DWORD;
  397.   I: Integer;
  398.   Info: TRegKeyInfo;
  399.   S: string;
  400. begin
  401.   Strings.Clear;
  402.   if GetKeyInfo(Info) then
  403.   begin
  404.     SetString(S, nil, Info.MaxValueLen + 1);
  405.     for I := 0 to Info.NumValues - 1 do
  406.     begin
  407.       Len := Info.MaxValueLen + 1;
  408.       RegEnumValue(CurrentKey, I, PChar(S), Len, nil, nil, nil, nil);
  409.       Strings.Add(PChar(S));
  410.     end;
  411.   end;
  412. end;
  413.  
  414. function TRegistry.GetDataInfo(const ValueName: string; var Value: TRegDataInfo): Boolean;
  415. var
  416.   DataType: Integer;
  417. begin
  418.   FillChar(Value, SizeOf(TRegDataInfo), 0);
  419.   Result := RegQueryValueEx(CurrentKey, PChar(ValueName), nil, @DataType, nil,
  420.     @Value.DataSize) = ERROR_SUCCESS;
  421.   Value.RegData := DataTypeToRegData(DataType);
  422. end;
  423.  
  424. function TRegistry.GetDataSize(const ValueName: string): Integer;
  425. var
  426.   Info: TRegDataInfo;
  427. begin
  428.   if GetDataInfo(ValueName, Info) then
  429.     Result := Info.DataSize else
  430.     Result := -1;
  431. end;
  432.  
  433. function TRegistry.GetDataType(const ValueName: string): TRegDataType;
  434. var
  435.   Info: TRegDataInfo;
  436. begin
  437.   if GetDataInfo(ValueName, Info) then
  438.     Result := Info.RegData else
  439.     Result := rdUnknown;
  440. end;
  441.  
  442. procedure TRegistry.WriteString(const Name, Value: string);
  443. begin
  444.   PutData(Name, PChar(Value), Length(Value)+1, rdString);
  445. end;
  446.  
  447. procedure TRegistry.WriteExpandString(const Name, Value: string);
  448. begin
  449.   PutData(Name, PChar(Value), Length(Value)+1, rdExpandString);
  450. end;
  451.  
  452. function TRegistry.ReadString(const Name: string): string;
  453. var
  454.   Len: Integer;
  455.   RegData: TRegDataType;
  456. begin
  457.   Len := GetDataSize(Name);
  458.   if Len > 0 then
  459.   begin
  460.     SetString(Result, nil, Len);
  461.     GetData(Name, PChar(Result), Len, RegData);
  462.     if (RegData = rdString) or (RegData = rdExpandString) then
  463.       SetLength(Result, StrLen(PChar(Result)))
  464.     else ReadError(Name);
  465.   end
  466.   else Result := '';
  467. end;
  468.  
  469. procedure TRegistry.WriteInteger(const Name: string; Value: Integer);
  470. begin
  471.   PutData(Name, @Value, SizeOf(Integer), rdInteger);
  472. end;
  473.  
  474. function TRegistry.ReadInteger(const Name: string): Integer;
  475. var
  476.   RegData: TRegDataType;
  477. begin
  478.   GetData(Name, @Result, SizeOf(Integer), RegData);
  479.   if RegData <> rdInteger then ReadError(Name);
  480. end;
  481.  
  482. procedure TRegistry.WriteBool(const Name: string; Value: Boolean);
  483. begin
  484.   WriteInteger(Name, Ord(Value));
  485. end;
  486.  
  487. function TRegistry.ReadBool(const Name: string): Boolean;
  488. begin
  489.   Result := ReadInteger(Name) <> 0;
  490. end;
  491.  
  492. procedure TRegistry.WriteFloat(const Name: string; Value: Double);
  493. begin
  494.   PutData(Name, @Value, SizeOf(Double), rdBinary);
  495. end;
  496.  
  497. function TRegistry.ReadFloat(const Name: string): Double;
  498. var
  499.   Len: Integer;
  500.   RegData: TRegDataType;
  501. begin
  502.   Len := GetData(Name, @Result, SizeOf(Double), RegData);
  503.   if (RegData <> rdBinary) or (Len <> SizeOf(Double)) then
  504.     ReadError(Name);
  505. end;
  506.  
  507. procedure TRegistry.WriteCurrency(const Name: string; Value: Currency);
  508. begin
  509.   PutData(Name, @Value, SizeOf(Currency), rdBinary);
  510. end;
  511.  
  512. function TRegistry.ReadCurrency(const Name: string): Currency;
  513. var
  514.   Len: Integer;
  515.   RegData: TRegDataType;
  516. begin
  517.   Len := GetData(Name, @Result, SizeOf(Currency), RegData);
  518.   if (RegData <> rdBinary) or (Len <> SizeOf(Currency)) then
  519.     ReadError(Name);
  520. end;
  521.  
  522. procedure TRegistry.WriteDateTime(const Name: string; Value: TDateTime);
  523. begin
  524.   PutData(Name, @Value, SizeOf(TDateTime), rdBinary);
  525. end;
  526.  
  527. function TRegistry.ReadDateTime(const Name: string): TDateTime;
  528. var
  529.   Len: Integer;
  530.   RegData: TRegDataType;
  531. begin
  532.   Len := GetData(Name, @Result, SizeOf(TDateTime), RegData);
  533.   if (RegData <> rdBinary) or (Len <> SizeOf(TDateTime)) then
  534.     ReadError(Name);
  535. end;
  536.  
  537. procedure TRegistry.WriteDate(const Name: string; Value: TDateTime);
  538. begin
  539.   WriteDateTime(Name, Value);
  540. end;
  541.  
  542. function TRegistry.ReadDate(const Name: string): TDateTime;
  543. begin
  544.   Result := ReadDateTime(Name);
  545. end;
  546.  
  547. procedure TRegistry.WriteTime(const Name: string; Value: TDateTime);
  548. begin
  549.   WriteDateTime(Name, Value);
  550. end;
  551.  
  552. function TRegistry.ReadTime(const Name: string): TDateTime;
  553. begin
  554.   Result := ReadDateTime(Name);
  555. end;
  556.  
  557. procedure TRegistry.WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
  558. begin
  559.   PutData(Name, @Buffer, BufSize, rdBinary);
  560. end;
  561.  
  562. function TRegistry.ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
  563. var
  564.   RegData: TRegDataType;
  565.   Info: TRegDataInfo;
  566. begin
  567.   if GetDataInfo(Name, Info) then
  568.   begin
  569.     Result := Info.DataSize;
  570.     RegData := Info.RegData;
  571.     if ((RegData = rdBinary) or (RegData = rdUnknown)) and (Result <= BufSize) then
  572.       GetData(Name, @Buffer, Result, RegData)
  573.     else ReadError(Name);
  574.   end else
  575.     Result := 0;
  576. end;
  577.  
  578. procedure TRegistry.PutData(const Name: string; Buffer: Pointer;
  579.   BufSize: Integer; RegData: TRegDataType);
  580. var
  581.   DataType: Integer;
  582. begin
  583.   DataType := RegDataToDataType(RegData);
  584.   if RegSetValueEx(CurrentKey, PChar(Name), 0, DataType, Buffer,
  585.     BufSize) <> ERROR_SUCCESS then
  586.     raise ERegistryException.CreateResFmt(@SRegSetDataFailed, [Name]);
  587. end;
  588.  
  589. function TRegistry.GetData(const Name: string; Buffer: Pointer;
  590.   BufSize: Integer; var RegData: TRegDataType): Integer;
  591. var
  592.   DataType: Integer;
  593. begin
  594.   DataType := REG_NONE;
  595.   if RegQueryValueEx(CurrentKey, PChar(Name), nil, @DataType, PByte(Buffer),
  596.     @BufSize) <> ERROR_SUCCESS then
  597.     raise ERegistryException.CreateResFmt(@SRegGetDataFailed, [Name]);
  598.   Result := BufSize;
  599.   RegData := DataTypeToRegData(DataType);
  600. end;
  601.  
  602. function TRegistry.HasSubKeys: Boolean;
  603. var
  604.   Info: TRegKeyInfo;
  605. begin
  606.   Result := GetKeyInfo(Info) and (Info.NumSubKeys > 0);
  607. end;
  608.  
  609. function TRegistry.ValueExists(const Name: string): Boolean;
  610. var
  611.   Info: TRegDataInfo;
  612. begin
  613.   Result := GetDataInfo(Name, Info);
  614. end;
  615.  
  616. function TRegistry.GetKey(const Key: string): HKEY;
  617. var
  618.   S: string;
  619.   Relative: Boolean;
  620. begin
  621.   S := Key;
  622.   Relative := IsRelative(S);
  623.   if not Relative then Delete(S, 1, 1);
  624.   Result := 0;
  625.   RegOpenKeyEx(GetBaseKey(Relative), PChar(S), 0, FAccess, Result);
  626. end;
  627.  
  628. function TRegistry.RegistryConnect(const UNCName: string): Boolean;
  629. var
  630.   TempKey: HKEY;
  631. begin
  632.   Result := RegConnectRegistry(PChar(UNCname), RootKey, TempKey) = ERROR_SUCCESS;
  633.   if Result then
  634.   begin
  635.     RootKey := TempKey;
  636.     FCloseRootKey := True;
  637.   end;
  638. end;
  639.  
  640. function TRegistry.LoadKey(const Key, FileName: string): Boolean;
  641. var
  642.   S: string;
  643. begin
  644.   S := Key;
  645.   if not IsRelative(S) then Delete(S, 1, 1);
  646.   Result := RegLoadKey(RootKey, PChar(S), PChar(FileName)) = ERROR_SUCCESS;
  647. end;
  648.  
  649. function TRegistry.UnLoadKey(const Key: string): Boolean;
  650. var
  651.   S: string;
  652. begin
  653.   S := Key;
  654.   if not IsRelative(S) then Delete(S, 1, 1);
  655.   Result := RegUnLoadKey(RootKey, PChar(S)) = ERROR_SUCCESS;
  656. end;
  657.  
  658. function TRegistry.RestoreKey(const Key, FileName: string): Boolean;
  659. var
  660.   RestoreKey: HKEY;
  661. begin
  662.   Result := False;
  663.   RestoreKey := GetKey(Key);
  664.   if RestoreKey <> 0 then
  665.   try
  666.     Result := RegRestoreKey(RestoreKey, PChar(FileName), 0) = ERROR_SUCCESS;
  667.   finally
  668.     RegCloseKey(RestoreKey);
  669.   end;
  670. end;
  671.  
  672. function TRegistry.ReplaceKey(const Key, FileName, BackUpFileName: string): Boolean;
  673. var
  674.   S: string;
  675.   Relative: Boolean;
  676. begin
  677.   S := Key;
  678.   Relative := IsRelative(S);
  679.   if not Relative then Delete(S, 1, 1);
  680.   Result := RegReplaceKey(GetBaseKey(Relative), PChar(S),
  681.     PChar(FileName), PChar(BackUpFileName)) = ERROR_SUCCESS;
  682. end;
  683.  
  684. function TRegistry.SaveKey(const Key, FileName: string): Boolean;
  685. var
  686.   SaveKey: HKEY;
  687. begin
  688.   Result := False;
  689.   SaveKey := GetKey(Key);
  690.   if SaveKey <> 0 then
  691.   try
  692.     Result := RegSaveKey(SaveKey, PChar(FileName), nil) = ERROR_SUCCESS;
  693.   finally
  694.     RegCloseKey(SaveKey);
  695.   end;
  696. end;
  697.  
  698. function TRegistry.KeyExists(const Key: string): Boolean;
  699. var
  700.   TempKey: HKEY;
  701. begin
  702.   TempKey := GetKey(Key);
  703.   if TempKey <> 0 then RegCloseKey(TempKey);
  704.   Result := TempKey <> 0;
  705. end;
  706.  
  707. procedure TRegistry.RenameValue(const OldName, NewName: string);
  708. var
  709.   Len: Integer;
  710.   RegData: TRegDataType;
  711.   Buffer: PChar;
  712. begin
  713.   if ValueExists(OldName) and not ValueExists(NewName) then
  714.   begin
  715.     Len := GetDataSize(OldName);
  716.     if Len > 0 then
  717.     begin
  718.       Buffer := AllocMem(Len);
  719.       try
  720.         Len := GetData(OldName, Buffer, Len, RegData);
  721.         DeleteValue(OldName);
  722.         PutData(NewName, Buffer, Len, RegData);
  723.       finally
  724.         FreeMem(Buffer);
  725.       end;
  726.     end;
  727.   end;
  728. end;
  729.  
  730. procedure TRegistry.MoveKey(const OldName, NewName: string; Delete: Boolean);
  731. var
  732.   SrcKey, DestKey: HKEY;
  733.  
  734.   procedure MoveValue(SrcKey, DestKey: HKEY; const Name: string);
  735.   var
  736.     Len: Integer;
  737.     OldKey, PrevKey: HKEY;
  738.     Buffer: PChar;
  739.     RegData: TRegDataType;
  740.   begin
  741.     OldKey := CurrentKey;
  742.     SetCurrentKey(SrcKey);
  743.     try
  744.       Len := GetDataSize(Name);
  745.       if Len > 0 then
  746.       begin
  747.         Buffer := AllocMem(Len);
  748.         try
  749.           Len := GetData(Name, Buffer, Len, RegData);
  750.           PrevKey := CurrentKey;
  751.           SetCurrentKey(DestKey);
  752.           try
  753.             PutData(Name, Buffer, Len, RegData);
  754.           finally
  755.             SetCurrentKey(PrevKey);
  756.           end;
  757.         finally
  758.           FreeMem(Buffer);
  759.         end;
  760.       end;
  761.     finally
  762.       SetCurrentKey(OldKey);
  763.     end;
  764.   end;
  765.  
  766.   procedure CopyValues(SrcKey, DestKey: HKEY);
  767.   var
  768.     Len: DWORD;
  769.     I: Integer;
  770.     KeyInfo: TRegKeyInfo;
  771.     S: string;
  772.     OldKey: HKEY;
  773.   begin
  774.     OldKey := CurrentKey;
  775.     SetCurrentKey(SrcKey);
  776.     try
  777.       if GetKeyInfo(KeyInfo) then
  778.       begin
  779.         MoveValue(SrcKey, DestKey, '');
  780.         SetString(S, nil, KeyInfo.MaxValueLen + 1);
  781.         for I := 0 to KeyInfo.NumValues - 1 do
  782.         begin
  783.           Len := KeyInfo.MaxValueLen + 1;
  784.           if RegEnumValue(SrcKey, I, PChar(S), Len, nil, nil, nil, nil) = ERROR_SUCCESS then
  785.             MoveValue(SrcKey, DestKey, PChar(S));
  786.         end;
  787.       end;
  788.     finally
  789.       SetCurrentKey(OldKey);
  790.     end;
  791.   end;
  792.  
  793.   procedure CopyKeys(SrcKey, DestKey: HKEY);
  794.   var
  795.     Len: DWORD;
  796.     I: Integer;
  797.     Info: TRegKeyInfo;
  798.     S: string;
  799.     OldKey, PrevKey, NewSrc, NewDest: HKEY;
  800.   begin
  801.     OldKey := CurrentKey;
  802.     SetCurrentKey(SrcKey);
  803.     try
  804.       if GetKeyInfo(Info) then
  805.       begin
  806.         SetString(S, nil, Info.MaxSubKeyLen + 1);
  807.         for I := 0 to Info.NumSubKeys - 1 do
  808.         begin
  809.           Len := Info.MaxSubKeyLen + 1;
  810.           if RegEnumKeyEx(SrcKey, I, PChar(S), Len, nil, nil, nil, nil) = ERROR_SUCCESS then
  811.           begin
  812.             NewSrc := GetKey(PChar(S));
  813.             if NewSrc <> 0 then
  814.             try
  815.               PrevKey := CurrentKey;
  816.               SetCurrentKey(DestKey);
  817.               try
  818.                 CreateKey(PChar(S));
  819.                 NewDest := GetKey(PChar(S));
  820.                 try
  821.                   CopyValues(NewSrc, NewDest);
  822.                   CopyKeys(NewSrc, NewDest);
  823.                 finally
  824.                   RegCloseKey(NewDest);
  825.                 end;
  826.               finally
  827.                 SetCurrentKey(PrevKey);
  828.               end;
  829.             finally
  830.               RegCloseKey(NewSrc);
  831.             end;
  832.           end;
  833.         end;
  834.       end;
  835.     finally
  836.       SetCurrentKey(OldKey);
  837.     end;
  838.   end;
  839.  
  840. begin
  841.   if KeyExists(OldName) and not KeyExists(NewName) then
  842.   begin
  843.     SrcKey := GetKey(OldName);
  844.     if SrcKey <> 0 then
  845.     try
  846.       CreateKey(NewName);
  847.       DestKey := GetKey(NewName);
  848.       if DestKey <> 0 then
  849.       try
  850.         CopyValues(SrcKey, DestKey);
  851.         CopyKeys(SrcKey, DestKey);
  852.         if Delete then DeleteKey(OldName);
  853.       finally
  854.         RegCloseKey(DestKey);
  855.       end;
  856.     finally
  857.       RegCloseKey(SrcKey);
  858.     end;
  859.   end;
  860. end;
  861.  
  862. { TRegIniFile }
  863.  
  864. constructor TRegIniFile.Create(const FileName: string);
  865. begin
  866.   Create(FileName, KEY_ALL_ACCESS);
  867. end;
  868.  
  869. constructor TRegIniFile.Create(const FileName: string; AAccess: LongWord);
  870. begin
  871.   inherited Create(AAccess);
  872.   FFilename := FileName;
  873.   OpenKey(FileName, True);
  874. end;
  875.  
  876. function TRegIniFile.ReadString(const Section, Ident, Default: string): string;
  877. var
  878.   Key, OldKey: HKEY;
  879. begin
  880.   Key := GetKey(Section);
  881.   if Key <> 0 then
  882.   try
  883.     OldKey := CurrentKey;
  884.     SetCurrentKey(Key);
  885.     try
  886.       if ValueExists(Ident) then
  887.         Result := inherited ReadString(Ident) else
  888.         Result := Default;
  889.     finally
  890.       SetCurrentKey(OldKey);
  891.     end;
  892.   finally
  893.     RegCloseKey(Key);
  894.   end
  895.   else Result := Default;
  896. end;
  897.  
  898. procedure TRegIniFile.WriteString(const Section, Ident, Value: String);
  899. var
  900.   Key, OldKey: HKEY;
  901. begin
  902.   CreateKey(Section);
  903.   Key := GetKey(Section);
  904.   if Key <> 0 then
  905.   try
  906.     OldKey := CurrentKey;
  907.     SetCurrentKey(Key);
  908.     try
  909.       inherited WriteString(Ident, Value);
  910.     finally
  911.       SetCurrentKey(OldKey);
  912.     end;
  913.   finally
  914.     RegCloseKey(Key);
  915.   end;
  916. end;
  917.  
  918. function TRegIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
  919. var
  920.   Key, OldKey: HKEY;
  921.   S: string;
  922. begin
  923.   Key := GetKey(Section);
  924.   if Key <> 0 then
  925.   try
  926.     OldKey := CurrentKey;
  927.     SetCurrentKey(Key);
  928.     try
  929.       if ValueExists(Ident) then
  930.       begin
  931.         S := inherited ReadString(Ident);
  932.         Result := StrToIntDef(S, Default);
  933.       end else
  934.         Result := Default;
  935.     finally
  936.       SetCurrentKey(OldKey);
  937.     end;
  938.   finally
  939.     RegCloseKey(Key);
  940.   end
  941.   else Result := Default;
  942. end;
  943.  
  944. procedure TRegIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
  945. var
  946.   Key, OldKey: HKEY;
  947. begin
  948.   CreateKey(Section);
  949.   Key := GetKey(Section);
  950.   if Key <> 0 then
  951.   try
  952.     OldKey := CurrentKey;
  953.     SetCurrentKey(Key);
  954.     try
  955.       inherited WriteString(Ident, IntToStr(Value));
  956.     finally
  957.       SetCurrentKey(OldKey);
  958.     end;
  959.   finally
  960.     RegCloseKey(Key);
  961.   end;
  962. end;
  963.  
  964. function TRegIniFile.ReadBool(const Section, Ident: string; Default: Boolean): Boolean;
  965. begin
  966.   Result := ReadInteger(Section, Ident, Ord(Default)) <> 0;
  967. end;
  968.  
  969. procedure TRegIniFile.WriteBool(const Section, Ident: string; Value: Boolean);
  970. const
  971.   Values: array[Boolean] of string = ('0', '1');
  972. var
  973.   Key, OldKey: HKEY;
  974. begin
  975.   CreateKey(Section);
  976.   Key := GetKey(Section);
  977.   if Key <> 0 then
  978.   try
  979.     OldKey := CurrentKey;
  980.     SetCurrentKey(Key);
  981.     try
  982.       inherited WriteString(Ident, Values[Value]);
  983.     finally
  984.       SetCurrentKey(OldKey);
  985.     end;
  986.   finally
  987.     RegCloseKey(Key);
  988.   end;
  989. end;
  990.  
  991. procedure TRegIniFile.ReadSection(const Section: string; Strings: TStrings);
  992. var
  993.   Key, OldKey: HKEY;
  994. begin
  995.   Key := GetKey(Section);
  996.   if Key <> 0 then
  997.   try
  998.     OldKey := CurrentKey;
  999.     SetCurrentKey(Key);
  1000.     try
  1001.       inherited GetValueNames(Strings);
  1002.     finally
  1003.       SetCurrentKey(OldKey);
  1004.     end;
  1005.   finally
  1006.     RegCloseKey(Key);
  1007.   end;
  1008. end;
  1009.  
  1010. procedure TRegIniFile.ReadSections(Strings: TStrings);
  1011. begin
  1012.   GetKeyNames(Strings);
  1013. end;
  1014.  
  1015. procedure TRegIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
  1016. var
  1017.   KeyList: TStringList;
  1018.   I: Integer;
  1019. begin
  1020.   KeyList := TStringList.Create;
  1021.   try
  1022.     ReadSection(Section, KeyList);
  1023.     Strings.BeginUpdate;
  1024.     try
  1025.       for I := 0 to KeyList.Count - 1 do
  1026.         Strings.Values[KeyList[I]] := ReadString(Section, KeyList[I], '');
  1027.     finally
  1028.       Strings.EndUpdate;
  1029.     end;
  1030.   finally
  1031.     KeyList.Free;
  1032.   end;
  1033. end;
  1034.  
  1035. procedure TRegIniFile.EraseSection(const Section: string);
  1036. begin
  1037.   inherited DeleteKey(Section);
  1038. end;
  1039.  
  1040. procedure TRegIniFile.DeleteKey(const Section, Ident: String);
  1041. var
  1042.   Key, OldKey: HKEY;
  1043. begin
  1044.   Key := GetKey(Section);
  1045.   if Key <> 0 then
  1046.   try
  1047.     OldKey := CurrentKey;
  1048.     SetCurrentKey(Key);
  1049.     try
  1050.       inherited DeleteValue(Ident);
  1051.     finally
  1052.       SetCurrentKey(OldKey);
  1053.     end;
  1054.   finally
  1055.     RegCloseKey(Key);
  1056.   end;
  1057. end;
  1058.  
  1059. { TRegistryIniFile }
  1060.  
  1061. constructor TRegistryIniFile.Create(const FileName: string);
  1062. begin
  1063.   Create(FileName, KEY_ALL_ACCESS);
  1064. end;
  1065.  
  1066. constructor TRegistryIniFile.Create(const FileName: string; AAccess: LongWord);
  1067. begin
  1068.   inherited Create(FileName);
  1069.   FRegIniFile := TRegIniFile.Create(FileName, AAccess);
  1070. end;
  1071.  
  1072. destructor TRegistryIniFile.Destroy;
  1073. begin
  1074.   FRegIniFile.Free;
  1075.   inherited Destroy;
  1076. end;
  1077.  
  1078. function TRegistryIniFile.ReadString(const Section, Ident, Default: string): string;
  1079. begin
  1080.   Result := FRegIniFile.ReadString(Section, Ident, Default);
  1081. end;
  1082.  
  1083. function TRegistryIniFile.ReadDate(const Section, Name: string; Default: TDateTime): TDateTime;
  1084. var
  1085.   Key, OldKey: HKEY;
  1086. begin
  1087.   with FRegIniFile do
  1088.   begin
  1089.     Key := GetKey(Section);
  1090.     if Key <> 0 then
  1091.     try
  1092.       OldKey := CurrentKey;
  1093.       SetCurrentKey(Key);
  1094.       try
  1095.         if ValueExists(Name) then
  1096.           Result := ReadDate(Name)
  1097.         else Result := Default;
  1098.       finally
  1099.         SetCurrentKey(OldKey);
  1100.       end;
  1101.     finally
  1102.       RegCloseKey(Key);
  1103.     end else Result := Default;
  1104.   end;
  1105. end;
  1106.  
  1107. function TRegistryIniFile.ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime;
  1108. var
  1109.   Key, OldKey: HKEY;
  1110. begin
  1111.   with FRegIniFile do
  1112.   begin
  1113.     Key := GetKey(Section);
  1114.     if Key <> 0 then
  1115.     try
  1116.       OldKey := CurrentKey;
  1117.       SetCurrentKey(Key);
  1118.       try
  1119.         if ValueExists(Name) then
  1120.           Result := ReadDateTime(Name)
  1121.         else Result := Default;
  1122.       finally
  1123.         SetCurrentKey(OldKey);
  1124.       end;
  1125.     finally
  1126.       RegCloseKey(Key);
  1127.     end else Result := Default;
  1128.   end;
  1129. end;
  1130.  
  1131. function TRegistryIniFile.ReadFloat(const Section, Name: string; Default: Double): Double;
  1132. var
  1133.   Key, OldKey: HKEY;
  1134. begin
  1135.   with FRegIniFile do
  1136.   begin
  1137.     Key := GetKey(Section);
  1138.     if Key <> 0 then
  1139.     try
  1140.       OldKey := CurrentKey;
  1141.       SetCurrentKey(Key);
  1142.       try
  1143.         if ValueExists(Name) then
  1144.           Result := ReadFloat(Name)
  1145.         else Result := Default;
  1146.       finally
  1147.         SetCurrentKey(OldKey);
  1148.       end;
  1149.     finally
  1150.       RegCloseKey(Key);
  1151.     end else Result := Default;
  1152.   end;
  1153. end;
  1154.  
  1155. function TRegistryIniFile.ReadInteger(const Section, Ident: string; Default: LongInt): LongInt;
  1156. var
  1157.   Key, OldKey: HKEY;
  1158. begin
  1159.   with TRegistry(FRegIniFile) do
  1160.   begin
  1161.     Key := GetKey(Section);
  1162.     if Key <> 0 then
  1163.     try
  1164.       OldKey := CurrentKey;
  1165.       SetCurrentKey(Key);
  1166.       try
  1167.         Result := Default;
  1168.         if ValueExists(Ident) then
  1169.           if GetDataType(Ident) = rdString then
  1170.             Result := StrToIntDef(ReadString(Ident), Default)
  1171.           else Result := ReadInteger(Ident);
  1172.       finally
  1173.         SetCurrentKey(OldKey);
  1174.       end;
  1175.     finally
  1176.       RegCloseKey(Key);
  1177.     end
  1178.     else Result := Default;
  1179.   end;
  1180. end;
  1181.  
  1182. function TRegistryIniFile.ReadTime(const Section, Name: string; Default: TDateTime): TDateTime;
  1183. var
  1184.   Key, OldKey: HKEY;
  1185. begin
  1186.   with FRegIniFile do
  1187.   begin
  1188.     Key := GetKey(Section);
  1189.     if Key <> 0 then
  1190.     try
  1191.       OldKey := CurrentKey;
  1192.       SetCurrentKey(Key);
  1193.       try
  1194.         if ValueExists(Name) then
  1195.           Result := ReadTime(Name)
  1196.         else Result := Default;
  1197.       finally
  1198.         SetCurrentKey(OldKey);
  1199.       end;
  1200.     finally
  1201.       RegCloseKey(Key);
  1202.     end else Result := Default;
  1203.   end;
  1204. end;
  1205.  
  1206. procedure TRegistryIniFile.WriteDate(const Section, Name: string; Value: TDateTime);
  1207. var
  1208.   Key, OldKey: HKEY;
  1209. begin
  1210.   with FRegIniFile do
  1211.   begin
  1212.     CreateKey(Section);
  1213.     Key := GetKey(Section);
  1214.     if Key <> 0 then
  1215.     try
  1216.       OldKey := CurrentKey;
  1217.       SetCurrentKey(Key);
  1218.       try
  1219.         WriteDate(Name, Value);
  1220.       finally
  1221.         SetCurrentKey(OldKey);
  1222.       end;
  1223.     finally
  1224.       RegCloseKey(Key);
  1225.     end;
  1226.   end;
  1227. end;
  1228.  
  1229. procedure TRegistryIniFile.WriteDateTime(const Section, Name: string; Value: TDateTime);
  1230. var
  1231.   Key, OldKey: HKEY;
  1232. begin
  1233.   with FRegIniFile do
  1234.   begin
  1235.     CreateKey(Section);
  1236.     Key := GetKey(Section);
  1237.     if Key <> 0 then
  1238.     try
  1239.       OldKey := CurrentKey;
  1240.       SetCurrentKey(Key);
  1241.       try
  1242.         WriteDateTime(Name, Value);
  1243.       finally
  1244.         SetCurrentKey(OldKey);
  1245.       end;
  1246.     finally
  1247.       RegCloseKey(Key);
  1248.     end;
  1249.   end;
  1250. end;
  1251.  
  1252. procedure TRegistryIniFile.WriteFloat(const Section, Name: string; Value: Double);
  1253. var
  1254.   Key, OldKey: HKEY;
  1255. begin
  1256.   with FRegIniFile do
  1257.   begin
  1258.     CreateKey(Section);
  1259.     Key := GetKey(Section);
  1260.     if Key <> 0 then
  1261.     try
  1262.       OldKey := CurrentKey;
  1263.       SetCurrentKey(Key);
  1264.       try
  1265.         WriteFloat(Name, Value);
  1266.       finally
  1267.         SetCurrentKey(OldKey);
  1268.       end;
  1269.     finally
  1270.       RegCloseKey(Key);
  1271.     end;
  1272.   end;
  1273. end;
  1274.  
  1275. procedure TRegistryIniFile.WriteInteger(const Section, Ident: string; Value: LongInt);
  1276. var
  1277.   Key, OldKey: HKEY;
  1278. begin
  1279.   with TRegistry(FRegIniFile) do
  1280.   begin
  1281.     CreateKey(Section);
  1282.     Key := GetKey(Section);
  1283.     if Key <> 0 then
  1284.     try
  1285.       OldKey := CurrentKey;
  1286.       SetCurrentKey(Key);
  1287.       try
  1288.         if ValueExists(Ident) and (GetDataType(Ident) = rdString) then
  1289.           WriteString(Ident, IntToStr(Value))
  1290.         else WriteInteger(Ident, Value);
  1291.       finally
  1292.         SetCurrentKey(OldKey);
  1293.       end;
  1294.     finally
  1295.       RegCloseKey(Key);
  1296.     end;
  1297.   end;
  1298. end;
  1299.  
  1300. procedure TRegistryIniFile.WriteTime(const Section, Name: string; Value: TDateTime);
  1301. var
  1302.   Key, OldKey: HKEY;
  1303. begin
  1304.   with FRegIniFile do
  1305.   begin
  1306.     CreateKey(Section);
  1307.     Key := GetKey(Section);
  1308.     if Key <> 0 then
  1309.     try
  1310.       OldKey := CurrentKey;
  1311.       SetCurrentKey(Key);
  1312.       try
  1313.         WriteTime(Name, Value);
  1314.       finally
  1315.         SetCurrentKey(OldKey);
  1316.       end;
  1317.     finally
  1318.       RegCloseKey(Key);
  1319.     end;
  1320.   end;
  1321. end;
  1322.  
  1323. procedure TRegistryIniFile.WriteString(const Section, Ident, Value: String);
  1324. begin
  1325.   FRegIniFile.WriteString(Section, Ident, Value);
  1326. end;
  1327.  
  1328. procedure TRegistryIniFile.ReadSection(const Section: string; Strings: TStrings);
  1329. begin
  1330.   FRegIniFile.ReadSection(Section, Strings);
  1331. end;
  1332.  
  1333. procedure TRegistryIniFile.ReadSections(Strings: TStrings);
  1334. begin
  1335.   FRegIniFile.ReadSections(Strings);
  1336. end;
  1337.  
  1338. procedure TRegistryIniFile.ReadSectionValues(const Section: string; Strings: TStrings);
  1339. begin
  1340.   FRegIniFile.ReadSectionValues(Section, Strings);
  1341. end;
  1342.  
  1343. procedure TRegistryIniFile.EraseSection(const Section: string);
  1344. begin
  1345.   FRegIniFile.EraseSection(Section);
  1346. end;
  1347.  
  1348. procedure TRegistryIniFile.DeleteKey(const Section, Ident: String);
  1349. begin
  1350.   FRegIniFile.DeleteKey(Section, Ident);
  1351. end;
  1352.  
  1353. procedure TRegistryIniFile.UpdateFile;
  1354. begin
  1355.   { Do nothing }
  1356. end;
  1357.  
  1358. end.
  1359.  
  1360.  
  1361.