diff --git a/PythonForDelphi/Components/PythonVCL_XE2.dpk b/PythonForDelphi/Components/PythonVCL_XE2.dpk index b2a06d00..5519aca8 100644 --- a/PythonForDelphi/Components/PythonVCL_XE2.dpk +++ b/PythonForDelphi/Components/PythonVCL_XE2.dpk @@ -31,7 +31,7 @@ requires vcl, dbrtl, bdertl, - Python_XE2; + Python_XE7; contains PythonDatabase in 'Sources\VCL\PythonDatabase.pas', diff --git a/PythonForDelphi/Components/Sources/Core/Definition.Inc b/PythonForDelphi/Components/Sources/Core/Definition.Inc index 11515028..635bfc77 100644 --- a/PythonForDelphi/Components/Sources/Core/Definition.Inc +++ b/PythonForDelphi/Components/Sources/Core/Definition.Inc @@ -2,7 +2,7 @@ (* *) (* Module: 'Definition.Inc' Copyright (c) 1998 *) (* *) -(* Version: 1.5 Dr. Dietmar Budelsky *) +(* Version: 1.6 Dr. Dietmar Budelsky *) (* budelsky@ibs.bm.eunet.de *) (* IBS Schillings GmbH & Co KG *) (* Ein Unternehmen der KROHNE-Gruppe *) @@ -36,6 +36,7 @@ //{$DEFINE PYTHON32} //{$DEFINE PYTHON33} //{$DEFINE PYTHON34} +//{$DEFINE PYTHON35} ///////////////////////////////////////////////////////////////////////////// // Python for Delphi settings. Comment out the setting you want to enable. @@ -314,6 +315,28 @@ {$DEFINE DELPHIXE7_OR_HIGHER} {$DEFINE DELPHIXE8_OR_HIGHER} {$ENDIF} +{$IFDEF VER300} // Delphi X "10" Seattle + {$DEFINE DELPHIX} + {$DEFINE DELPHI4_OR_HIGHER} + {$DEFINE DELPHI5_OR_HIGHER} + {$DEFINE DELPHI6_OR_HIGHER} + {$DEFINE DELPHI7_OR_HIGHER} + {$DEFINE DELPHI8_OR_HIGHER} + {$DEFINE DELPHI2005_OR_HIGHER} + {$DEFINE DELPHI2006_OR_HIGHER} + {$DEFINE DELPHI2007_OR_HIGHER} + {$DEFINE DELPHI2009_OR_HIGHER} + {$DEFINE DELPHI2010_OR_HIGHER} + {$DEFINE DELPHIXE_OR_HIGHER} + {$DEFINE DELPHIXE2_OR_HIGHER} + {$DEFINE DELPHIXE3_OR_HIGHER} + {$DEFINE DELPHIXE4_OR_HIGHER} + {$DEFINE DELPHIXE5_OR_HIGHER} + {$DEFINE DELPHIXE6_OR_HIGHER} + {$DEFINE DELPHIXE7_OR_HIGHER} + {$DEFINE DELPHIXE8_OR_HIGHER} + {$DEFINE DELPHIX_OR_HIGHER} +{$ENDIF} ///////////////////////////////////////////////////////////////////////////// // Python versions ///////////////////////////////////////////////////////////////////////////// @@ -322,19 +345,21 @@ // Note that the installer will let the user specify its default Python version, and // thus will edit this file. -{$IFNDEF PYTHON34} - {$IFNDEF PYTHON33} - {$IFNDEF PYTHON32} - {$IFNDEF PYTHON31} - {$IFNDEF PYTHON30} - {$IFNDEF PYTHON27} - {$IFNDEF PYTHON26} - {$IFNDEF PYTHON25} - {$IFNDEF PYTHON24} - {$IFNDEF PYTHON23} - {------} - {$DEFINE PYTHON27} - {------} +{$IFNDEF PYTHON35} + {$IFNDEF PYTHON34} + {$IFNDEF PYTHON33} + {$IFNDEF PYTHON32} + {$IFNDEF PYTHON31} + {$IFNDEF PYTHON30} + {$IFNDEF PYTHON27} + {$IFNDEF PYTHON26} + {$IFNDEF PYTHON25} + {$IFNDEF PYTHON24} + {$IFNDEF PYTHON23} + {------} + {$DEFINE PYTHON27} + {------} + {$ENDIF} {$ENDIF} {$ENDIF} {$ENDIF} @@ -416,6 +441,18 @@ {$DEFINE PYTHON33_OR_HIGHER} {$DEFINE PYTHON34_OR_HIGHER} {$ENDIF} +{$IFDEF PYTHON35} + {$DEFINE PYTHON23_OR_HIGHER} + {$DEFINE PYTHON24_OR_HIGHER} + {$DEFINE PYTHON25_OR_HIGHER} + {$DEFINE PYTHON26_OR_HIGHER} + {$DEFINE PYTHON30_OR_HIGHER} + {$DEFINE PYTHON31_OR_HIGHER} + {$DEFINE PYTHON32_OR_HIGHER} + {$DEFINE PYTHON33_OR_HIGHER} + {$DEFINE PYTHON34_OR_HIGHER} + {$DEFINE PYTHON35_OR_HIGHER} +{$ENDIF} ///////////////////////////////////////////////////////////////////////////// // Misc @@ -442,4 +479,3 @@ {$ENDIF DARWIN} {$ENDIF FPC} - diff --git a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas index 9900134a..1de7ebeb 100644 --- a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas +++ b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas @@ -126,7 +126,7 @@ interface end; const {$IFDEF MSWINDOWS} - PYTHON_KNOWN_VERSIONS: array[1..10] of TPythonVersionProp = + PYTHON_KNOWN_VERSIONS: array[1..11] of TPythonVersionProp = ( (DllName: 'python23.dll'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True), (DllName: 'python24.dll'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True), (DllName: 'python25.dll'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True), @@ -136,10 +136,11 @@ interface (DllName: 'python31.dll'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True), (DllName: 'python32.dll'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True), (DllName: 'python33.dll'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True), - (DllName: 'python34.dll'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True) ); + (DllName: 'python34.dll'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True), + (DllName: 'python35.dll'; RegVersion: '3.5'; APIVersion: 1013; CanUseLatest: True) ); {$ENDIF} {$IFDEF LINUX} - PYTHON_KNOWN_VERSIONS: array[1..10] of TPythonVersionProp = + PYTHON_KNOWN_VERSIONS: array[1..11] of TPythonVersionProp = ( (DllName: 'libpython2.3.so'; RegVersion: '2.3'; APIVersion: 1012; CanUseLatest: True), (DllName: 'libpython2.4.so'; RegVersion: '2.4'; APIVersion: 1012; CanUseLatest: True), (DllName: 'libpython2.5.so'; RegVersion: '2.5'; APIVersion: 1013; CanUseLatest: True), @@ -149,7 +150,8 @@ interface (DllName: 'libpython3.1.so'; RegVersion: '3.1'; APIVersion: 1013; CanUseLatest: True), (DllName: 'libpython3.2.so'; RegVersion: '3.2'; APIVersion: 1013; CanUseLatest: True), (DllName: 'libpython3.3.so'; RegVersion: '3.3'; APIVersion: 1013; CanUseLatest: True), - (DllName: 'libpython3.4.so'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True) ); + (DllName: 'libpython3.4.so'; RegVersion: '3.4'; APIVersion: 1013; CanUseLatest: True), + (DllName: 'libpython3.5.so'; RegVersion: '3.5'; APIVersion: 1013; CanUseLatest: True) ); {$ENDIF} {$IFDEF PYTHON23} COMPILED_FOR_PYTHON_VERSION_INDEX = 1; @@ -180,6 +182,9 @@ interface {$ENDIF} {$IFDEF PYTHON34} COMPILED_FOR_PYTHON_VERSION_INDEX = 10; +{$ENDIF} +{$IFDEF PYTHON35} + COMPILED_FOR_PYTHON_VERSION_INDEX = 11; {$ENDIF} PYT_METHOD_BUFFER_INCREASE = 10; PYT_MEMBER_BUFFER_INCREASE = 10; @@ -1374,7 +1379,7 @@ EPyWindowsError = class (EPyOSError); {$IF not Defined(FPC) and (CompilerVersion >= 23)} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] - {$IFEND} + {$ENDIF} TPythonInputOutput = class(TComponent) protected FMaxLines : Integer; @@ -1679,6 +1684,9 @@ TPythonInterface=class(TDynamicDll) PyArg_Parse: function( args: PPyObject; format: PAnsiChar {;....}) : Integer; cdecl varargs; PyArg_ParseTuple: function( args: PPyObject; format: PAnsiChar {;...}): Integer; cdecl varargs; Py_BuildValue: function( format: PAnsiChar {;...}): PPyObject; cdecl varargs; + + Py_SetPythonHome: procedure( home: PAnsiChar); cdecl; + Py_Initialize: procedure; cdecl; Py_Exit: procedure( RetVal: Integer); cdecl; PyEval_GetBuiltins: function: PPyObject; cdecl; @@ -2115,7 +2123,7 @@ TPythonTraceback = class {$IF not Defined(FPC) and (CompilerVersion >= 23)} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] - {$IFEND} + {$ENDIF} TPythonEngine = class(TPythonInterface) private FInitScript: TStrings; @@ -2583,7 +2591,7 @@ TErrors = class(TCollection) {$IF not Defined(FPC) and (CompilerVersion >= 23)} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] - {$IFEND} + {$ENDIF} TPythonModule = class(TMethodsContainer) protected FModuleName : AnsiString; @@ -2848,7 +2856,7 @@ TTypeServices = class(TPersistent) // that creates instances of itself. {$IF not Defined(FPC) and (CompilerVersion >= 23)} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] - {$IFEND} + {$ENDIF} TPythonType = class(TGetSetContainer) protected FType : PyTypeObject; @@ -2936,7 +2944,7 @@ TPythonType = class(TGetSetContainer) {$IF not Defined(FPC) and (CompilerVersion >= 23)} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] - {$IFEND} + {$ENDIF} TPythonDelphiVar = class( TEngineClient ) protected FModule : AnsiString; @@ -3093,6 +3101,7 @@ function PyType_HasFeature(AType : PPyTypeObject; AFlag : Integer) : Boolean; {$IFDEF MSWINDOWS} function IsPythonVersionRegistered(PythonVersion : string; out InstallPath: string; out AllUserInstall: Boolean) : Boolean; +function GetPythonHome(): string; {$ENDIF} (* Mask FPU Excptions - Useful for importing SciPy and other Python libs @@ -3738,6 +3747,9 @@ procedure TPythonInterface.MapDll; PyArg_ParseTuple := Import('PyArg_ParseTuple'); Py_BuildValue := Import('Py_BuildValue'); Py_Initialize := Import('Py_Initialize'); + Py_SetPythonHome := Import('Py_SetPythonHome'); + + PyDict_New := Import('PyDict_New'); PyDict_SetItemString := Import('PyDict_SetItemString'); PyModule_GetDict := Import('PyModule_GetDict'); @@ -4761,6 +4773,7 @@ procedure TPythonEngine.Initialize; var i : Integer; + PythonVersion: string; begin if Assigned(gPythonEngine) then raise Exception.Create('There is already one instance of TPythonEngine running' ); @@ -4790,6 +4803,11 @@ procedure TPythonEngine.Initialize; end end; AssignPyFlags; + PythonVersion := Format('%s.%s', [IntToStr(gPythonEngine.FMajorVersion), IntToStr(gPythonEngine.FMinorVersion)]); + if PythonVersion = '2.7' then + Py_SetPythonHome(PAnsiChar(AnsiString(GetPythonHome()))); + //Py_SetPythonHome('C:\Python27_32'); + //end; Py_Initialize; FInitialized := True; FIORedirected := False; @@ -4895,6 +4913,7 @@ procedure TPythonEngine.CheckRegistry; begin // try a current user installation RootKey := HKEY_CURRENT_USER; + key := Format('\Software\Python\PythonCore\%s-32\PythonPath', [RegVersion]); // current only 32bit if not KeyExists( key ) then begin if Assigned( FOnPathInitialization ) then @@ -9678,17 +9697,48 @@ function IsPythonVersionRegistered(PythonVersion : string; // since it may not be on the system path. var key: string; + PythonVersionFloat: Single; + errorPos: Integer; + + // 3way operator function. + function IfThen(condition: Boolean; ifT, ifF: Cardinal): Cardinal; overload; + begin + if condition then + Result := ifT + else + Result := ifF; + end; + + function IfThen(condition: Boolean; ifT, ifF: string): string; overload; + begin + if condition then + Result := ifT + else + Result := ifF; + end; + begin + Result := False; InstallPath := ''; AllUserInstall := False; + //PythonVersionFloat := StrToFloat(PythonVersion); + Val(PythonVersion, PythonVersionFloat, errorPos); try - key := Format('\Software\Python\PythonCore\%s\InstallPath', [PythonVersion]); + + // 3.5 + key := Format('\Software\Python\PythonCore\%s\InstallPath', [IfThen(PythonVersionFloat < 3.5, PythonVersion, PythonVersion {$IFDEF WIN32}+ '-32'{$ENDIF})]); + with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do try - RootKey := HKEY_LOCAL_MACHINE; + + RootKey := IfThen(PythonVersionFloat < 3.5, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER); // python 3.5 => root registry key change + if KeyExists(key) then begin AllUserInstall := True; + if (PythonVersionFloat >= 3.5) then + if OpenKey(Key, False) then + InstallPath := ReadString(''); // python version 3.5 up Result := True; end; finally @@ -9701,7 +9751,7 @@ function IsPythonVersionRegistered(PythonVersion : string; if not AllUserInstall then with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do try - RootKey := HKEY_CURRENT_USER; + RootKey := IfThen(PythonVersionFloat < 3.5, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER); if OpenKey(Key, False) then begin InstallPath := ReadString(''); Result := True; @@ -9710,6 +9760,25 @@ function IsPythonVersionRegistered(PythonVersion : string; Free; end; end; + + +// for only 2.7 +function GetPythonHome(): string; +var + temp: Boolean; + key: string; +begin + with TRegistry.Create(KEY_READ and not KEY_NOTIFY) do + try + RootKey := HKEY_LOCAL_MACHINE; + key := Format('\Software\Python\PythonCore\%s\InstallPath', ['2.7']); + if OpenKey(Key, False) then + Result := ReadString(''); + finally + Free; + end; +end; + {$ENDIF} end. diff --git a/PythonForDelphi/Components/Sources/VCL/pyDB.pas b/PythonForDelphi/Components/Sources/VCL/pyDB.pas index 0e109e53..3bb9205a 100644 --- a/PythonForDelphi/Components/Sources/VCL/pyDB.pas +++ b/PythonForDelphi/Components/Sources/VCL/pyDB.pas @@ -180,8 +180,15 @@ TPyDataset = class(TCommon) function Repr : PPyObject; override; // Sequence services +{$IFDEF DELPHI2009_OR_HIGHER} + function SqLength : NativeInt; override; + function SqItem( idx : NativeInt ) : PPyObject; override; +{$ELSE} function SqLength : Integer; override; function SqItem( idx : Integer ) : PPyObject; override; +{$ENDIF} + + // Class methods class procedure RegisterMethods( PythonType : TPythonType ); override; @@ -1629,8 +1636,11 @@ function TPyDataset.Repr : PPyObject; end; // Sequence services - +{$IFDEF DELPHI2009_OR_HIGHER} +function TPyDataset.SqLength : NativeInt; +{$ELSE} function TPyDataset.SqLength : Integer; +{$ENDIF} begin if CheckDataset then Result := Dataset.RecordCount @@ -1638,7 +1648,11 @@ function TPyDataset.SqLength : Integer; Result := -1; end; +{$IFDEF DELPHI2009_OR_HIGHER} +function TPyDataset.SqItem( idx : NativeInt ) : PPyObject; +{$ELSE} function TPyDataset.SqItem( idx : Integer ) : PPyObject; +{$ENDIF} begin if CheckDataset then begin