@@ -4899,37 +4899,48 @@ procedure TPythonEngine.Notification( AComponent: TComponent;
48994899procedure TPythonEngine.CheckRegistry ;
49004900{ $IFDEF MSWINDOWS}
49014901var
4902- key : String;
4903- path : String;
4902+ key : string;
4903+ Path : string;
4904+ NewPath : string;
4905+ MajorVersion : integer;
4906+ MinorVersion : integer;
4907+ VersionSuffix: string;
49044908{ $ENDIF}
49054909begin
49064910{ $IFDEF MSWINDOWS}
4911+ if Assigned( FOnPathInitialization ) then
49074912 try
4908- with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
4913+ with TRegistry.Create(KEY_ALL_ACCESS and not KEY_NOTIFY) do
49094914 try
4910- // Access := KEY_READ; // works only with Delphi5 or greater
4915+ MajorVersion := StrToInt(RegVersion[1 ]);
4916+ MinorVersion := StrToInt(RegVersion[3 ]);
4917+ VersionSuffix := ' ' ;
4918+ { $IFDEF CPUX86}
4919+ if (MajorVersion > 3 ) or ((MajorVersion = 3 ) and (MinorVersion >= 5 )) then
4920+ VersionSuffix := ' -32' ;
4921+ { $ENDIF}
4922+ key := Format(' \Software\Python\PythonCore\%s%s\PythonPath' , [RegVersion, VersionSuffix]);
4923+
49114924 RootKey := HKEY_LOCAL_MACHINE;
4912- key := Format(' \Software\Python\PythonCore\%s\PythonPath' , [RegVersion]);
49134925 if not KeyExists( key ) then
4926+ begin
4927+ // try a current user installation
4928+ RootKey := HKEY_CURRENT_USER;
4929+ if not KeyExists( key ) then Exit;
4930+ end ;
4931+ // Key found
4932+ OpenKey( key, True );
4933+ try
4934+ Path := ReadString(' ' );
4935+ NewPath := Path;
4936+ FOnPathInitialization( Self, NewPath );
4937+ if NewPath <> Path then
49144938 begin
4915- // try a current user installation
4916- RootKey := HKEY_CURRENT_USER;
4917- if not KeyExists( key ) then
4918- begin
4919- if Assigned( FOnPathInitialization ) then
4920- begin
4921- path := ' ' ;
4922- FOnPathInitialization( Self, path );
4923- if path <> ' ' then
4924- begin
4925- // Access := KEY_ALL_ACCESS; // works only with Delphi5 or greater
4926- OpenKey( key, True );
4927- WriteString( ' ' , path );
4928- CloseKey;
4929- end ;
4930- end ;
4931- end ;
4939+ WriteString( ' ' , NewPath );
49324940 end ;
4941+ finally
4942+ CloseKey;
4943+ end ;
49334944 finally
49344945 Free;
49354946 end ;
0 commit comments