@@ -4899,37 +4899,48 @@ procedure TPythonEngine.Notification( AComponent: TComponent;
4899
4899
procedure TPythonEngine.CheckRegistry ;
4900
4900
{ $IFDEF MSWINDOWS}
4901
4901
var
4902
- key : String;
4903
- path : String;
4902
+ key : string;
4903
+ Path : string;
4904
+ NewPath : string;
4905
+ MajorVersion : integer;
4906
+ MinorVersion : integer;
4907
+ VersionSuffix: string;
4904
4908
{ $ENDIF}
4905
4909
begin
4906
4910
{ $IFDEF MSWINDOWS}
4911
+ if Assigned( FOnPathInitialization ) then
4907
4912
try
4908
- with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
4913
+ with TRegistry.Create(KEY_ALL_ACCESS and not KEY_NOTIFY) do
4909
4914
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
+
4911
4924
RootKey := HKEY_LOCAL_MACHINE;
4912
- key := Format(' \Software\Python\PythonCore\%s\PythonPath' , [RegVersion]);
4913
4925
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
4914
4938
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 );
4932
4940
end ;
4941
+ finally
4942
+ CloseKey;
4943
+ end ;
4933
4944
finally
4934
4945
Free;
4935
4946
end ;
0 commit comments