@@ -9698,47 +9698,59 @@ function IsPythonVersionRegistered(PythonVersion : string;
9698
9698
9699
9699
// The above convension was changed in Python 3.5. Now even for all user
9700
9700
// installations the dll is located at the InstallPath.
9701
+ // Also from version 3.5 onwards 32 bit version have a suffix -32 e.g. "3.6-32"
9702
+ // See also PEP 514
9701
9703
9702
9704
var
9703
9705
key: string;
9706
+ VersionSuffix: string;
9704
9707
MajorVersion : integer;
9705
9708
MinorVersion : integer;
9706
9709
begin
9707
9710
Result := False;
9708
9711
InstallPath := ' ' ;
9709
9712
AllUserInstall := False;
9713
+ MajorVersion := StrToInt(PythonVersion[1 ]);
9714
+ MinorVersion := StrToInt(PythonVersion[3 ]);
9715
+ VersionSuffix := ' ' ;
9716
+ { $IFDEF CPUX86}
9717
+ if (MajorVersion > 3 ) or ((MajorVersion = 3 ) and (MinorVersion >= 5 )) then
9718
+ VersionSuffix := ' -32' ;
9719
+ { $ENDIF}
9720
+ key := Format(' \Software\Python\PythonCore\%s%s\InstallPath' , [PythonVersion, VersionSuffix]);
9721
+
9722
+ // First try HKEY_CURRENT_USER as per PEP514
9710
9723
try
9711
- key := Format(' \Software\Python\PythonCore\%s\InstallPath' , [PythonVersion]);
9712
9724
with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
9713
9725
try
9714
- RootKey := HKEY_LOCAL_MACHINE ;
9715
- if KeyExists(key ) then begin
9716
- AllUserInstall := True ;
9726
+ RootKey := HKEY_CURRENT_USER ;
9727
+ if OpenKey(Key, False ) then begin
9728
+ InstallPath := ReadString( ' ' ) ;
9717
9729
Result := True;
9718
- MajorVersion := StrToInt(PythonVersion[1 ]);
9719
- MinorVersion := StrToInt(PythonVersion[3 ]);
9720
- if (MajorVersion > 3 ) or ((MajorVersion = 3 ) and (MinorVersion >= 5 )) then
9721
- if OpenKey(Key, False) then
9722
- InstallPath := ReadString(' ' );
9730
+ Exit;
9723
9731
end ;
9724
9732
finally
9725
9733
Free;
9726
9734
end ;
9727
9735
except
9728
9736
end ;
9729
- // We do not seem to have an All User Python Installation.
9730
- // Check whether we have a current user installation
9731
- if not AllUserInstall then
9737
+
9738
+ // Then try for an all user installation
9739
+ try
9732
9740
with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do
9733
9741
try
9734
- RootKey := HKEY_CURRENT_USER ;
9742
+ RootKey := HKEY_LOCAL_MACHINE ;
9735
9743
if OpenKey(Key, False) then begin
9736
- InstallPath := ReadString(' ' );
9744
+ AllUserInstall := True;
9745
+ if (MajorVersion > 3 ) or ((MajorVersion = 3 ) and (MinorVersion >= 5 )) then
9746
+ InstallPath := ReadString(' ' );
9737
9747
Result := True;
9738
9748
end ;
9739
9749
finally
9740
9750
Free;
9741
9751
end ;
9752
+ except
9753
+ end ;
9742
9754
end ;
9743
9755
{ $ENDIF}
9744
9756
0 commit comments