Browse Source

* To be Delphi compatible TRegistry.DeleteKey() must delete the specified key and all its child keys.

git-svn-id: trunk@48207 -
(cherry picked from commit ffff24593df898d7880b58f336df4b42a18f28e0)
yury 4 years ago
parent
commit
324061745a
1 changed files with 21 additions and 0 deletions
  1. 21 0
      packages/fcl-registry/src/winreg.inc

+ 21 - 0
packages/fcl-registry/src/winreg.inc

@@ -70,7 +70,28 @@ function TRegistry.DeleteKey(const Key: UnicodeString): Boolean;
 
 
 Var
 Var
   u: UnicodeString;
   u: UnicodeString;
+  subkeys: TUnicodeStringArray;
+  k, old: HKEY;
+  i: integer;
 begin
 begin
+  old:=fCurrentKey;
+  k:=GetKey(Key);
+  if k <> 0 then
+    begin
+      fCurrentKey:=k;
+      try
+        subkeys:=GetKeyNames;
+        for i:=0 to High(subkeys) do
+          begin
+            Result:=DeleteKey(subkeys[i]);
+            if not Result then
+              exit;
+          end;
+      finally
+        fCurrentKey:=old;
+        CloseKey(k);
+      end;
+    end;
   u:=PRepKey(Key);
   u:=PRepKey(Key);
   FLastError:=RegDeleteKeyW(GetBaseKey(RelativeKey(Key)),PWideChar(u));
   FLastError:=RegDeleteKeyW(GetBaseKey(RelativeKey(Key)),PWideChar(u));
   Result:=FLastError=ERROR_SUCCESS;
   Result:=FLastError=ERROR_SUCCESS;