From 30587299ea290ed23669ba95a96e1d1503a347b3 Mon Sep 17 00:00:00 2001 From: yury Date: Tue, 19 Jan 2021 17:38:36 +0000 Subject: [PATCH] * 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 - --- packages/fcl-registry/src/regini.inc | 45 +++++++++++++++------------ packages/fcl-registry/src/registry.pp | 2 ++ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/fcl-registry/src/regini.inc b/packages/fcl-registry/src/regini.inc index 665e24ba4e..4163a57c9b 100644 --- a/packages/fcl-registry/src/regini.inc +++ b/packages/fcl-registry/src/regini.inc @@ -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; diff --git a/packages/fcl-registry/src/registry.pp b/packages/fcl-registry/src/registry.pp index eba09c093a..91177376e1 100644 --- a/packages/fcl-registry/src/registry.pp +++ b/packages/fcl-registry/src/registry.pp @@ -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