* TRegIniFile: When accessing a section do not change/close the current open key.

* TRegIniFile should work properly with the XML registry. The tregistry2 test should work on any platform.

git-svn-id: trunk@48210 -
This commit is contained in:
yury 2021-01-19 17:38:36 +00:00
parent 5d69ba2cd8
commit 30587299ea
2 changed files with 27 additions and 20 deletions

View File

@ -293,31 +293,36 @@ end;
function TRegIniFile.OpenSection(const Section: string; CreateSection : Boolean = false): boolean; function TRegIniFile.OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
var var
k: HKEY; s: string;
S : String;
begin begin
S:=Section; ASSERT(fOldCurKey = 0);
If (S<>'') and (S[1] = '\') then if Section <> '' then begin
Delete(S,1,1); fOldCurKey:=CurrentKey;
if CreateSection and (S<>'') then fOldCurPath:=CurrentPath;
CreateKey('\'+CurrentPath+'\'+S); // Detach the current key to prevent its closing in OpenKey()
if S <> '' then SetCurrentKey(0);
k:=GetKey('\'+CurrentPath+'\'+S) if Section[1] = '\' then
s:=Section
else else
k:=GetKey('\'+CurrentPath); s:='\' + string(fOldCurPath) + '\' + Section;
if k = 0 then Result:=OpenKey(s, CreateSection);
begin if not Result then begin
Result:=False; // Restore on error
exit; SetCurrentKey(fOldCurKey);
fOldCurKey:=0;
fOldCurPath:='';
end; end;
SetCurrentKey(k); end
else
Result:=True; Result:=True;
end; end;
procedure TRegIniFile.CloseSection; procedure TRegIniFile.CloseSection;
begin begin
CloseKey(CurrentKey); if fOldCurKey <> 0 then begin
fCurrentKey:=0; ChangeKey(fOldCurKey, fOldCurPath);
fOldCurKey:=0;
fOldCurPath:='';
end;
end; end;

View File

@ -202,6 +202,8 @@ type
fFileName : String; fFileName : String;
fPath : String; fPath : String;
fPreferStringValues: Boolean; fPreferStringValues: Boolean;
fOldCurKey : HKEY;
fOldCurPath : UnicodeString;
function OpenSection(const Section: string; CreateSection : Boolean = false): boolean; function OpenSection(const Section: string; CreateSection : Boolean = false): boolean;
procedure CloseSection; procedure CloseSection;
public public