@@ -20,12 +20,14 @@ TPythonVersion = record
20
20
private
21
21
FDisplayName: string;
22
22
FHelpFile: string;
23
+ fSysArchitecture : string;
23
24
function GetDLLName : string;
24
- function GetSysArchitecture :string;
25
+ function ExpectedArchitecture :string;
25
26
function GetIsPython3K : Boolean;
26
27
function GetHelpFile : string;
27
28
function GetDisplayName : string;
28
29
function GetApiVersion : integer;
30
+ function GetSysArchitecture : string;
29
31
public
30
32
IsRegistered: Boolean;
31
33
IsAllUsers: Boolean;
@@ -55,12 +57,12 @@ TPythonVersion = record
55
57
56
58
{ $IFDEF MSWINDOWS}
57
59
(* Checks whether a Python version is registered and returns the related info *)
58
- function GetRegisterPythonVersion (SysVersion: string;
60
+ function GetRegisteredPythonVersion (SysVersion: string;
59
61
out PythonVersion: TPythonVersion): Boolean;
60
62
(* Returns all registered Python versions *)
61
63
function GetRegisteredPythonVersions : TPythonVersions;
62
64
(* Returns the highest numbered registered Python version *)
63
- function GetLatestRegisteredPythonVersion (PythonVersion: TPythonVersion): Boolean;
65
+ function GetLatestRegisteredPythonVersion (out PythonVersion: TPythonVersion): Boolean;
64
66
{ $ENDIF}
65
67
66
68
implementation
@@ -85,7 +87,7 @@ function TPythonVersion.GetDLLName: string;
85
87
{ $ENDIF}
86
88
end ;
87
89
88
- function TPythonVersion.GetSysArchitecture : string;
90
+ function TPythonVersion.ExpectedArchitecture : string;
89
91
begin
90
92
Result := ' ' ;
91
93
{ $IFDEF CPUX64}
@@ -154,6 +156,13 @@ function TPythonVersion.GetIsPython3K: Boolean;
154
156
end ;
155
157
end ;
156
158
159
+ function TPythonVersion.GetSysArchitecture : string;
160
+ begin
161
+ Result := fSysArchitecture;
162
+ if Result = ' ' then
163
+ Result := ' Unknown' ;
164
+ end ;
165
+
157
166
function CompareVersions (A, B : String) : Integer;
158
167
159
168
function GetNextNumber (var Version: string): Integer;
@@ -197,7 +206,7 @@ function CompareVersions(A, B : String) : Integer;
197
206
end ;
198
207
199
208
{ $IFDEF MSWINDOWS}
200
- function GetRegisterPythonVersion (SysVersion: string;
209
+ function GetRegisteredPythonVersion (SysVersion: string;
201
210
out PythonVersion: TPythonVersion): Boolean;
202
211
// Python provides for All user and Current user installations
203
212
// All User installations place the Python DLL in the Windows System directory
@@ -233,6 +242,7 @@ function GetRegisterPythonVersion(SysVersion: string;
233
242
if OpenKey(Key, False) then begin
234
243
PythonVersion.DisplayName := ReadString(' DisplayName' );
235
244
PythonVersion.Version := ReadString(' Version' );
245
+ PythonVersion.fSysArchitecture := ReadString(' SysArchitecture' );
236
246
CloseKey;
237
247
end ;
238
248
if OpenKey(Key + ' \PythonPath' , False) then begin
@@ -260,10 +270,10 @@ function GetRegisterPythonVersion(SysVersion: string;
260
270
FillChar(PythonVersion, SizeOf(TPythonVersion), 0 );
261
271
262
272
VersionSuffix := ' ' ;
263
- { $IFDEF CPUX86}
273
+ { $IFDEF CPUX86}
264
274
if CompareVersions(SysVersion, ' 3.5' ) <= 0 then
265
275
VersionSuffix := ' -32' ;
266
- { $ENDIF}
276
+ { $ENDIF}
267
277
key := Format(' \Software\Python\PythonCore\%s%s' , [SysVersion, VersionSuffix]);
268
278
269
279
@@ -276,6 +286,10 @@ function GetRegisterPythonVersion(SysVersion: string;
276
286
if not Result then begin
277
287
PythonVersion.IsAllUsers := True;
278
288
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;
279
293
end ;
280
294
281
295
PythonVersion.IsRegistered := Result;
@@ -290,22 +304,21 @@ function GetRegisteredPythonVersions : TPythonVersions;
290
304
Count := 0 ;
291
305
SetLength(Result, High(PYTHON_KNOWN_VERSIONS) - COMPILED_FOR_PYTHON_VERSION_INDEX + 1 );
292
306
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
294
308
begin
295
309
Result[Count] := PythonVersion;
296
310
Inc(Count);
297
311
end ;
298
312
SetLength(Result, Count);
299
313
end ;
300
314
301
- function GetLatestRegisteredPythonVersion (PythonVersion: TPythonVersion): Boolean;
315
+ function GetLatestRegisteredPythonVersion (out PythonVersion: TPythonVersion): Boolean;
302
316
Var
303
317
I: Integer;
304
318
begin
305
- Result := False;
306
319
for I := High(PYTHON_KNOWN_VERSIONS) downto COMPILED_FOR_PYTHON_VERSION_INDEX do
307
320
begin
308
- Result := GetRegisterPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
321
+ Result := GetRegisteredPythonVersion (PYTHON_KNOWN_VERSIONS[I].RegVersion, PythonVersion);
309
322
if Result then break;
310
323
end ;
311
324
end ;
0 commit comments