Răsfoiți Sursa

KeyExists did not work for virtual keys in INI file

Source commit: c86f743db34e95dfadaaef671404bf1c6ac89366
Martin Prikryl 6 ani în urmă
părinte
comite
bca358e5b4
2 a modificat fișierele cu 22 adăugiri și 17 ștergeri
  1. 21 17
      source/core/HierarchicalStorage.cpp
  2. 1 0
      source/core/HierarchicalStorage.h

+ 21 - 17
source/core/HierarchicalStorage.cpp

@@ -946,29 +946,33 @@ void __fastcall TCustomIniFileStorage::SetAccessMode(TStorageAccessMode value)
   THierarchicalStorage::SetAccessMode(value);
 }
 //---------------------------------------------------------------------------
-bool __fastcall TCustomIniFileStorage::DoOpenSubKey(const UnicodeString & SubKey, bool CanCreate)
+bool __fastcall TCustomIniFileStorage::DoKeyExistsInternal(const UnicodeString & SubKey)
 {
-  bool Result = CanCreate;
-
-  if (!Result)
-  {
-    CacheSections();
-    UnicodeString NewKey = ExcludeTrailingBackslash(CurrentSubKey+SubKey);
-    if (FSections->Count > 0)
+  CacheSections();
+  bool Result = false;
+  UnicodeString NewKey = ExcludeTrailingBackslash(CurrentSubKey + SubKey);
+  if (FSections->Count > 0)
+  {
+    int Index = -1;
+    Result = FSections->Find(NewKey, Index);
+    if (!Result &&
+        (Index < FSections->Count) &&
+        (FSections->Strings[Index].SubString(1, NewKey.Length()+1) == NewKey + L"\\"))
     {
-      int Index = -1;
-      Result = FSections->Find(NewKey, Index);
-      if (!Result &&
-          (Index < FSections->Count) &&
-          (FSections->Strings[Index].SubString(1, NewKey.Length()+1) == NewKey + L"\\"))
-      {
-        Result = true;
-      }
+      Result = true;
     }
   }
   return Result;
 }
 //---------------------------------------------------------------------------
+bool __fastcall TCustomIniFileStorage::DoOpenSubKey(const UnicodeString & SubKey, bool CanCreate)
+{
+  bool Result =
+    CanCreate ||
+    DoKeyExistsInternal(SubKey);
+  return Result;
+}
+//---------------------------------------------------------------------------
 bool __fastcall TCustomIniFileStorage::OpenRootKey(bool CanCreate)
 {
   // Not supported with master storage.
@@ -1093,7 +1097,7 @@ bool __fastcall TCustomIniFileStorage::DoKeyExists(const UnicodeString & SubKey,
 {
   return
     (HandleByMasterStorage() && FMasterStorage->DoKeyExists(SubKey, AForceAnsi)) ||
-    FIniFile->SectionExists(CurrentSubKey + MungeStr(SubKey, AForceAnsi, false));
+    DoKeyExistsInternal(MungeStr(SubKey, AForceAnsi, false));
 }
 //---------------------------------------------------------------------------
 bool __fastcall TCustomIniFileStorage::DoValueExistsInternal(const UnicodeString & Value)

+ 1 - 0
source/core/HierarchicalStorage.h

@@ -219,6 +219,7 @@ protected:
 
   void __fastcall CacheSections();
   void __fastcall ResetCache();
+  bool __fastcall DoKeyExistsInternal(const UnicodeString & SubKey);
 };
 //---------------------------------------------------------------------------
 class TIniFileStorage : public TCustomIniFileStorage