Browse Source

* Implemented CurrentPath property.
* Fixed handle leak when calling OpenKey() for already opened registry.

git-svn-id: trunk@22652 -

yury 12 years ago
parent
commit
7607cc06de
1 changed files with 16 additions and 10 deletions
  1. 16 10
      packages/fcl-registry/src/winreg.inc

+ 16 - 10
packages/fcl-registry/src/winreg.inc

@@ -177,7 +177,7 @@ Var
   Handle: HKEY;
   Handle: HKEY;
   Disposition: Integer;
   Disposition: Integer;
   SecurityAttributes: Pointer; //LPSECURITY_ATTRIBUTES;
   SecurityAttributes: Pointer; //LPSECURITY_ATTRIBUTES;
-
+  S: string;
 begin
 begin
   SecurityAttributes := Nil;
   SecurityAttributes := Nil;
   P:=PrepKey(Key);
   P:=PrepKey(Key);
@@ -194,21 +194,27 @@ begin
   else
   else
     Result:=RegOpenKeyExA(GetBaseKey(RelativeKey(Key)),
     Result:=RegOpenKeyExA(GetBaseKey(RelativeKey(Key)),
                          P,0,fAccess,Handle)=ERROR_SUCCESS;
                          P,0,fAccess,Handle)=ERROR_SUCCESS;
-  If Result then
-    fCurrentKey:=Handle;
+  If Result then begin
+    if RelativeKey(Key) then
+      S:=CurrentPath + Key
+    else
+      S:=P;
+    ChangeKey(Handle, S);
+  end;
 end;
 end;
 
 
 function TRegistry.OpenKeyReadOnly(const Key: string): Boolean;
 function TRegistry.OpenKeyReadOnly(const Key: string): Boolean;
 
 
 Var
 Var
-  P: PChar;
-  Handle: HKEY;
-
+  OldAccess: LongWord;
 begin
 begin
-  P:=PrepKey(Key);
-  Result := RegOpenKeyExA(GetBaseKey(RelativeKey(Key)),P,0,KEY_READ,Handle) = 0;
-  If Result Then
-    fCurrentKey := Handle;
+  OldAccess:=fAccess;
+  fAccess:=KEY_READ;
+  try
+    Result:=OpenKey(Key, False);
+  finally
+    fAccess:=OldAccess;
+  end;
 end;
 end;
 
 
 function TRegistry.RegistryConnect(const UNCName: string): Boolean;
 function TRegistry.RegistryConnect(const UNCName: string): Boolean;