@@ -20,12 +20,14 @@ TPythonVersion = record
2020 private
2121 FDisplayName: string;
2222 FHelpFile: string;
23+ fSysArchitecture : string;
2324 function GetDLLName : string;
24- function GetSysArchitecture :string;
25+ function ExpectedArchitecture :string;
2526 function GetIsPython3K : Boolean;
2627 function GetHelpFile : string;
2728 function GetDisplayName : string;
2829 function GetApiVersion : integer;
30+ function GetSysArchitecture : string;
2931 public
3032 IsRegistered: Boolean;
3133 IsAllUsers: Boolean;
@@ -55,12 +57,12 @@ TPythonVersion = record
5557
5658 { $IFDEF MSWINDOWS}
5759 (* Checks whether a Python version is registered and returns the related info *)
58- function GetRegisterPythonVersion (SysVersion: string;
60+ function GetRegisteredPythonVersion (SysVersion: string;
5961 out PythonVersion: TPythonVersion): Boolean;
6062 (* Returns all registered Python versions *)
6163 function GetRegisteredPythonVersions : TPythonVersions;
6264 (* Returns the highest numbered registered Python version *)
63- function GetLatestRegisteredPythonVersion (PythonVersion: TPythonVersion): Boolean;
65+ function GetLatestRegisteredPythonVersion (out PythonVersion: TPythonVersion): Boolean;
6466 { $ENDIF}
6567
6668implementation
@@ -85,7 +87,7 @@ function TPythonVersion.GetDLLName: string;
8587 { $ENDIF}
8688end ;
8789
88- function TPythonVersion.GetSysArchitecture : string;
90+ function TPythonVersion.ExpectedArchitecture : string;
8991begin
9092 Result := ' ' ;
9193 { $IFDEF CPUX64}
@@ -154,6 +156,13 @@ function TPythonVersion.GetIsPython3K: Boolean;
154156 end ;
155157end ;
156158
159+ function TPythonVersion.GetSysArchitecture : string;
160+ begin
161+ Result := fSysArchitecture;
162+ if Result = ' ' then
163+ Result := ' Unknown' ;
164+ end ;
165+
157166function CompareVersions (A, B : String) : Integer;
158167
159168 function GetNextNumber (var Version: string): Integer;
@@ -197,7 +206,7 @@ function CompareVersions(A, B : String) : Integer;
197206end ;
198207
199208{ $IFDEF MSWINDOWS}
200- function GetRegisterPythonVersion (SysVersion: string;
209+ function GetRegisteredPythonVersion (SysVersion: string;
201210 out PythonVersion: TPythonVersion): Boolean;
202211 // Python provides for All user and Current user installations
203212 // All User installations place the Python DLL in the Windows System directory
@@ -233,6 +242,7 @@ function GetRegisterPythonVersion(SysVersion: string;
233242 if OpenKey(Key, False) then begin
234243 PythonVersion.DisplayName := ReadString(' DisplayName' );
235244 PythonVersion.Version := ReadString(' Version' );
245+ PythonVersion.fSysArchitecture := ReadString(' SysArchitecture' );
236246 CloseKey;
237247 end ;
238248 if OpenKey(Key + ' \PythonPath' , False) then begin
@@ -260,10 +270,10 @@ function GetRegisterPythonVersion(SysVersion: string;
260270 FillChar(PythonVersion, SizeOf(TPythonVersion), 0 );
261271
262272 VersionSuffix := ' ' ;
263- { $IFDEF CPUX86}
273+ { $IFDEF CPUX86}
264274 if CompareVersions(SysVersion, ' 3.5' ) <= 0 then
265275 VersionSuffix := ' -32' ;
266- { $ENDIF}
276+ { $ENDIF}
267277 key := Format(' \Software\Python\PythonCore\%s%s' , [SysVersion, VersionSuffix]);
268278
269279
@@ -276,6 +286,10 @@ function GetRegisterPythonVersion(SysVersion: string;
276286 if not Result then begin
277287 PythonVersion.IsAllUsers := True;
278288 Result := ReadFromRegistry(HKEY_LOCAL_MACHINE, key);
289+ if PythonVersion.fSysArchitecture = ' ' then
290+ // for all user installations we can be sure.
291+ // / But not for local user installations
292+ PythonVersion.fSysArchitecture := PythonVersion.ExpectedArchitecture;
279293 end ;
280294
281295 PythonVersion.IsRegistered := Result;
@@ -290,22 +304,21 @@ function GetRegisteredPythonVersions : TPythonVersions;
290304 Count := 0 ;
291305 SetLength(Result, High(PYTHON_KNOWN_VERSIONS) - COMPILED_FOR_PYTHON_VERSION_INDEX + 1 );
292306 for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do
293- if GetRegisterPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion) then
307+ if GetRegisteredPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion) then
294308 begin
295309 Result[Count] := PythonVersion;
296310 Inc(Count);
297311 end ;
298312 SetLength(Result, Count);
299313end ;
300314
301- function GetLatestRegisteredPythonVersion (PythonVersion: TPythonVersion): Boolean;
315+ function GetLatestRegisteredPythonVersion (out PythonVersion: TPythonVersion): Boolean;
302316Var
303317 I: Integer;
304318begin
305- Result := False;
306319 for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do
307320 begin
308- Result := GetRegisterPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
321+ Result := GetRegisteredPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
309322 if Result then break;
310323 end ;
311324end ;
0 commit comments