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

View File

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