Repeated call to TRegistry.OpenKey ignore absolute registry Key path
Original Reporter info from Mantis: chronos
-
Reporter name:
Original Reporter info from Mantis: chronos
- Reporter name:
Description:
This is specific to Linux implementation of registry using XML file.
Steps to reproduce:
Here is sample code where OpenKey is executed repeatedly for single TRegistry instance. It should set absolute path for example to \Software\Vendor\Application\List\0 but in fact in next turn it set path relative to
\Software\Vendor\Application\List\0\Software\Vendor\Application\List\1. This works properly on windows for winreg implementation but wrong on Linux xmlreg.
procedure SaveToRegistry;
var
I: Integer;
begin
with TRegistry.Create do
try
RootKey := HKEY_CURRENT_USER;
for I := 0 to 4 do begin
OpenKey('\Software\Vendor\Application\List\' + IntToStr(I), True);
WriteString('Name', 'Item ' + IntToStr(I));
end;
finally
Free;
end;
end;
Additional information:
In fcl-registry\src\xmlreg.pp in
Function TXmlRegistry.SetKey(KeyPath : String; AllowCreate : Boolean) : boolean;
there is code which give answer for wrong behaviour. If SetKey is called to xmlreg instance multiple times it use last FCurrentElement instead to set root start element for key path starting with slash .
...
If (FCurrentElement<>nil) then
begin
Delete(Keypath,1,1);
Node:=FCurrentElement;
Resultkey:=FCurrentKey;
end
else
begin
Delete(Keypath,1,1);
Node:=FDocument.DocumentElement;
If (FRootKey<>'') then
KeyPath:=FRootKey+KeyPath;
ResultKey:='';
end;
..
Then solution would be something to reset FCurrentElement for every OpenKey method call in xregreg.ini
function TRegistry.OpenKey(const Key: string; CanCreate: Boolean): Boolean;
begin
if Pos('\', Key) = 1 then TXmlRegistry(FSysData).RootKey := '';
Result:=TXmlRegistry(FSysData).SetKey(Key,CanCreate);
FCurrentKey:=1;
end;
Mantis conversion info:
- Mantis ID: 20761
- Platform: Linux
- Version: 2.4.4
- Fixed in version: 3.0.0
- Fixed in revision: 26695 (#628689e3)
- Target version: 3.0.0