From 24d60dec76891019512d76c4d5b5468037eec8a4 Mon Sep 17 00:00:00 2001 From: zbyna Date: Sat, 4 Nov 2017 00:24:06 +0100 Subject: [PATCH 1/9] Fix compiling in Lazarus 1.7 svn 54250M --- .gitignore | 2 ++ .../Components/Sources/Core/PythonEngine.pas | 2 +- .../Components/Sources/Core/VarPyth.pas | 14 +++++++------- .../Components/Sources/Core/WrapDelphi.pas | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1d53aad3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +PythonForDelphi/Components/FPC_Units/ +PythonForDelphi/Components/Sources/Core/backup/ diff --git a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas index d47b8418..809d84e3 100644 --- a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas +++ b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas @@ -5824,7 +5824,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject; // detect if the variant supports this special property if Assigned(Disp) and (Disp.GetIDsOfNames(GUID_NULL, @wStr, 1, 0, @DispID) = S_OK) then begin - myInt := DeRefV.__asPPyObject__; //Returns the address to PPyObject as integer. (See impl. in PythonAtom.pas) + myInt := intptr(DeRefV.__asPPyObject__); //Returns the address to PPyObject as integer. (See impl. in PythonAtom.pas) Result := PPyObject(myInt); Py_XIncRef(Result); end diff --git a/PythonForDelphi/Components/Sources/Core/VarPyth.pas b/PythonForDelphi/Components/Sources/Core/VarPyth.pas index d3eb8ce1..7567781e 100644 --- a/PythonForDelphi/Components/Sources/Core/VarPyth.pas +++ b/PythonForDelphi/Components/Sources/Core/VarPyth.pas @@ -180,9 +180,9 @@ TPythonVariantType = class(TInvokeableVariantType, IVarInstanceReference) const Arguments: TVarDataArray): Boolean; override; function GetProperty(var Dest: TVarData; const V: TVarData; const AName: string): Boolean; override; - function SetProperty(const V: TVarData; const AName: string; + function SetProperty(var V: TVarData; const AName: String; // const V:TvarData const Value: TVarData): Boolean; override; - procedure DispInvoke(Dest: PVarData; const Source: TVarData; + procedure DispInvoke(Dest: PVarData; var Source: TVarData; //const Source: TVarData; CallDesc: PCallDesc; Params: Pointer); override; end; @@ -933,7 +933,7 @@ procedure SetClearVarToEmptyParam(var V: TVarData); {$IFDEF USESYSTEMDISPINVOKE} procedure TPythonVariantType.DispInvoke(Dest: PVarData; - const Source: TVarData; CallDesc: PCallDesc; Params: Pointer); + var Source: TVarData; CallDesc: PCallDesc; Params: Pointer); //const Source: TVarData; {$IFDEF DELPHIXE2} // Modified to correct memory leak QC102387 procedure PatchedDispInvoke(Dest: PVarData; @@ -1431,13 +1431,13 @@ function TPythonVariantType.EvalPython(const V: TVarData; if not Assigned(_value) then raise Exception.Create(SCantConvertValueToPythonObject); if PyList_Check(AObject) then - _result := PyList_SetItem( AObject, Variant(AKey), _value ) + _result := PyList_SetItem( AObject, IntPtr(Variant(AKey)), _value ) else if PyTuple_Check(AObject) then - _result := PyTuple_SetItem( AObject, Variant(AKey), _value ) + _result := PyTuple_SetItem( AObject, IntPtr(Variant(AKey)), _value ) else try if PySequence_Check(AObject) <> 0 then - _result := PySequence_SetItem(AObject, Variant(AKey), _value) + _result := PySequence_SetItem(AObject, IntPtr(Variant(AKey)), _value) else _result := PyObject_SetItem( AObject, _key, _value ); finally @@ -1855,7 +1855,7 @@ function TPythonVariantType.RightPromotion(const V: TVarData; Result := False; end; -function TPythonVariantType.SetProperty(const V: TVarData; +function TPythonVariantType.SetProperty(var V: TVarData; // const V: TVarData const AName: string; const Value: TVarData): Boolean; var _newValue : PPyObject; diff --git a/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas b/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas index 5e632be7..eb09585d 100644 --- a/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas +++ b/PythonForDelphi/Components/Sources/Core/WrapDelphi.pas @@ -1106,12 +1106,12 @@ function PythonToSet(ASet : PPyObject; APropInfo: PPropInfo) : Integer; {$IFDEF FPC} function GetPropValue(Instance: TObject; PropInfo: PPropInfo): Variant; begin - Result := Variants.GetPropValue(Instance, PropInfo^.Name); + Result := Variants.GetPropValue(Instance, PropInfo,True); // PropInfo^.Name end; procedure SetPropValue(Instance: TObject; PropInfo: PPropInfo; const Value: Variant); begin - Variants.SetPropValue(Instance, PropInfo^.Name, Value); + Variants.SetPropValue(Instance, PropInfo, Value); // PropInfo^.Name end; {$ENDIF} From 2fd1b9d207ebac2301350d25318f5b5695c53c8c Mon Sep 17 00:00:00 2001 From: zbyna Date: Sat, 12 May 2018 01:18:05 +0200 Subject: [PATCH 2/9] Fix compiling in Lazarus 1.7 svn 54250M --- PythonForDelphi/Components/Sources/Core/VarPyth.pas | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PythonForDelphi/Components/Sources/Core/VarPyth.pas b/PythonForDelphi/Components/Sources/Core/VarPyth.pas index 89137bd6..2b9b269f 100644 --- a/PythonForDelphi/Components/Sources/Core/VarPyth.pas +++ b/PythonForDelphi/Components/Sources/Core/VarPyth.pas @@ -1348,7 +1348,7 @@ function TPythonVariantType.GetPropertyWithArg(var Dest: TVarData; // So: myList[0] won't work, but myObj.MyList[0] will!!! if PySequence_Check(_prop) <> 0 then begin - _result := PySequence_GetItem(_prop, Variant(AArg)); + _result := PySequence_GetItem(_prop, IntPtr(Variant(AArg))); CheckError; end; // of if end; // of if @@ -1438,13 +1438,13 @@ function TPythonVariantType.EvalPython(const V: TVarData; if not Assigned(_value) then raise Exception.Create(SCantConvertValueToPythonObject); if PyList_Check(AObject) then - _result := PyList_SetItem( AObject, Variant(AKey), _value ) + _result := PyList_SetItem( AObject, IntPtr(Variant(AKey)), _value ) else if PyTuple_Check(AObject) then - _result := PyTuple_SetItem( AObject, Variant(AKey), _value ) + _result := PyTuple_SetItem( AObject, IntPtr(Variant(AKey)), _value ) else try if PySequence_Check(AObject) <> 0 then - _result := PySequence_SetItem(AObject, Variant(AKey), _value) + _result := PySequence_SetItem(AObject, IntPtr(Variant(AKey)), _value) else _result := PyObject_SetItem( AObject, _key, _value ); finally From 75da0443ca4110f339812053e79d51cd6346bffa Mon Sep 17 00:00:00 2001 From: zbyna Date: Sun, 13 May 2018 22:53:52 +0200 Subject: [PATCH 3/9] Adjust git ignore --- .gitignore | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 05dd19d8..a75051df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,64 @@ PythonForDelphi/Components/FPC_Units/ PythonForDelphi/Components/Sources/Core/backup/ + # Compiled source # ################### -*.dcu +* +.dcu + *.obj + *.exe + *.bpl + *.bpi + *.dcp + *.rsm + *.stat + *.map + # Generated source # ################### + *.hpp + # Backup files # ################### + *.~* -# IDE Files # + +#IDE Files # ################### -*.dproj.local +* +*.dproj +*.local + *.groupproj.local + *.identcache + *.dsk + *.tvsconfig + *.otares + *.drc + *.rc + *.res -*.local -# Output Folders # -################### -/Win32 -/Win64 -/OSX32 -/__history -*.bak -*.Patch -VirtualTreeView.zip -*.#00 -*.pch +*.local +*.pyd +*.res +*.lrs +*.lpi \ No newline at end of file From 8d714435f374684a4e7cfcadc3e5ac061f55bfbc Mon Sep 17 00:00:00 2001 From: zbyna Date: Mon, 14 May 2018 01:44:42 +0200 Subject: [PATCH 4/9] Disable searching registry on Windows to use embeddable official zip Windows x86 embeddable zip file from python.org --- .../Components/Sources/Core/PythonEngine.pas | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas index 74b8bced..18283dfb 100644 --- a/PythonForDelphi/Components/Sources/Core/PythonEngine.pas +++ b/PythonForDelphi/Components/Sources/Core/PythonEngine.pas @@ -90,7 +90,9 @@ interface {$ELSE} TinyWideStrings, {$ENDIF} - MethodCallBack; + MethodCallBack, + Dialogs, + Forms ; //####################################################### //## ## @@ -3362,10 +3364,10 @@ function TDynamicDll.GetDllPath : String; {$ENDIF} begin Result := DllPath; - {$IFDEF MSWINDOWS} if DLLPath = '' then begin - IsPythonVersionRegistered(RegVersion, Result, AllUserInstall); + DllPath:= ExtractFilePath(Application.ExeName); + //IsPythonVersionRegistered(RegVersion, Result, AllUserInstall); end; {$ENDIF} @@ -3386,7 +3388,7 @@ procedure TDynamicDll.OpenDll(const aDllName : String); FDLLHandle := 0; DoOpenDll(aDllName); - + //showmessage(format('path: %s name: %s',[dllPath,DllName])); if not IsHandleValid then begin {$IFDEF MSWINDOWS} s := Format('Error %d: Could not open Dll "%s"',[GetLastError, DllName]); From 0f4d3b441dbf675cc1a66e3726356a433f8e3201 Mon Sep 17 00:00:00 2001 From: zbyna Date: Mon, 14 May 2018 01:45:25 +0200 Subject: [PATCH 5/9] Fixing demo 1 --- PythonForDelphi/Demos/FPC/Demo01/project1.lpi | 118 ++++++++++++------ PythonForDelphi/Demos/FPC/Demo01/project1.res | Bin 138128 -> 138128 bytes PythonForDelphi/Demos/FPC/Demo01/unit1.lfm | 21 +++- PythonForDelphi/Demos/FPC/Demo01/unit1.lrs | 43 ++++--- 4 files changed, 121 insertions(+), 61 deletions(-) diff --git a/PythonForDelphi/Demos/FPC/Demo01/project1.lpi b/PythonForDelphi/Demos/FPC/Demo01/project1.lpi index bfc0f0d8..bb4b50ee 100644 --- a/PythonForDelphi/Demos/FPC/Demo01/project1.lpi +++ b/PythonForDelphi/Demos/FPC/Demo01/project1.lpi @@ -1,21 +1,87 @@ - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -42,17 +108,16 @@ - + - - + @@ -61,24 +126,19 @@ - - - - - - + @@ -87,11 +147,9 @@ - - - - - + + + @@ -99,9 +157,7 @@ - - - + @@ -109,20 +165,17 @@ - - - - - + + + + - - @@ -130,7 +183,6 @@ - @@ -146,12 +198,11 @@ - - + @@ -168,9 +219,6 @@ - - - diff --git a/PythonForDelphi/Demos/FPC/Demo01/project1.res b/PythonForDelphi/Demos/FPC/Demo01/project1.res index 7c6cf3e4be6fa881cb2f2caa9bda693328155c28..03adc0a9760b4a83f223e287ca76fde51c24a959 100644 GIT binary patch delta 89 zcmbQRonrzJDNKICEXKsiviT1)(G;P~7MmG*1YrDrhMmHxAW5NT*W2zuV1RK*a i0T4q$oT-3ias;y)kTbb~Ic1`P2#bLLC(A|)1!e%JDHnSH delta 110 zcmbQRonrzJDM*MjGcYJHFfjc8F9F1iKo$dofB*x-_5uke1?K5z#F^BX7#OC15ob!7 zs2~PpZnR*U1f-g6CT+Kw#OTHWWN&Yo#pvb)Vw}0dcuW< Date: Mon, 14 May 2018 01:46:43 +0200 Subject: [PATCH 6/9] Partially fix of demo6 --- PythonForDelphi/Demos/FPC/Demo06/Project1.lpi | 272 ++++++++++++++++-- PythonForDelphi/Demos/FPC/Demo06/Unit1.lfm | 43 +-- PythonForDelphi/Demos/FPC/Demo06/Unit1.pas | 6 +- 3 files changed, 271 insertions(+), 50 deletions(-) diff --git a/PythonForDelphi/Demos/FPC/Demo06/Project1.lpi b/PythonForDelphi/Demos/FPC/Demo06/Project1.lpi index 21a8b55f..8c7aa3fd 100644 --- a/PythonForDelphi/Demos/FPC/Demo06/Project1.lpi +++ b/PythonForDelphi/Demos/FPC/Demo06/Project1.lpi @@ -12,8 +12,76 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -35,13 +103,14 @@ - + - - - + + + + @@ -51,24 +120,25 @@ - - - + + + - + - - - - + + + + + @@ -77,7 +147,7 @@ - + @@ -85,15 +155,15 @@ - + - - - + + + @@ -101,18 +171,169 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -134,15 +355,6 @@ - - - - - - - - - diff --git a/PythonForDelphi/Demos/FPC/Demo06/Unit1.lfm b/PythonForDelphi/Demos/FPC/Demo06/Unit1.lfm index c02dca2b..f106d124 100644 --- a/PythonForDelphi/Demos/FPC/Demo06/Unit1.lfm +++ b/PythonForDelphi/Demos/FPC/Demo06/Unit1.lfm @@ -8,10 +8,10 @@ object Form1: TForm1 ClientHeight = 500 ClientWidth = 800 Color = clBtnFace + DesignTimePPI = 134 Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' - LCLVersion = '1.8.0.6' Visible = False object Splitter1: TSplitter Cursor = crVSplit @@ -31,17 +31,18 @@ object Form1: TForm1 Lines.Strings = ( 'import sys' 'import spam' - 'print spam.foo(''hello world'', 1)' + 'print(spam.foo(''hello world'', 1))' 'p = spam.CreatePoint( 10, 25 )' - 'print "Point:", p' + 'print( "Point:", p)' 'p.x = 58' - 'print p.x, p' + 'print( p.x, p)' 'p.OffsetBy( 5, 5 )' - 'print p' - 'print "Current value of var test is: ", test' + 'print(p)' + 'print("Current value of var test is: ", test)' 'test.Value = "New value set by Python"' - 'print "getdouble: ", spam.getdouble()' + 'print("getdouble: ", spam.getdouble())' ) + ParentFont = False ScrollBars = ssVertical TabOrder = 1 end @@ -54,6 +55,7 @@ object Form1: TForm1 BevelOuter = bvNone ClientHeight = 68 ClientWidth = 800 + ParentFont = False TabOrder = 0 object Button1: TButton Left = 40 @@ -62,6 +64,7 @@ object Form1: TForm1 Width = 115 Caption = 'Execute script' OnClick = Button1Click + ParentFont = False TabOrder = 0 end object Button2: TButton @@ -71,6 +74,7 @@ object Form1: TForm1 Width = 91 Caption = 'Load script...' OnClick = Button2Click + ParentFont = False TabOrder = 1 end object Button3: TButton @@ -80,6 +84,7 @@ object Form1: TForm1 Width = 89 Caption = 'Save script...' OnClick = Button3Click + ParentFont = False TabOrder = 2 end object Button4: TButton @@ -89,13 +94,15 @@ object Form1: TForm1 Width = 89 Caption = 'Show var test' OnClick = Button4Click + ParentFont = False TabOrder = 3 end object Edit1: TEdit Left = 500 - Height = 20 + Height = 28 Top = 8 Width = 150 + ParentFont = False TabOrder = 4 end end @@ -108,17 +115,19 @@ object Form1: TForm1 Lines.Strings = ( 'Memo2' ) + ParentFont = False TabOrder = 2 end object PythonEngine1: TPythonEngine InitScript.Strings = ( 'import sys' - 'print "Python Dll: ", sys.version' - 'print sys.copyright' + 'print("Python Dll: ", sys.version)' + 'print(sys.copyright)' 'print' ) IO = PythonGUIInputOutput1 - left = 8 + PyFlags = [pfIgnoreEnvironmentFlag] + Left = 8 end object PythonType1: TPythonType Engine = PythonEngine1 @@ -130,24 +139,24 @@ object Form1: TForm1 Services.Number = [] Services.Sequence = [] Services.Mapping = [] - left = 72 + Left = 72 end object PythonModule1: TPythonModule Engine = PythonEngine1 OnInitialization = PythonModule1Initialization ModuleName = 'spam' Errors = <> - left = 104 + Left = 104 end object OpenDialog1: TOpenDialog DefaultExt = '.*.py' Filter = 'Python files|*.py|Text files|*.txt|All files|*.*' - left = 176 + Left = 176 end object SaveDialog1: TSaveDialog DefaultExt = '.*.py' Filter = 'Python files|*.py|Text files|*.txt|All files|*.*' - left = 208 + Left = 208 end object PythonDelphiVar1: TPythonDelphiVar Engine = PythonEngine1 @@ -156,12 +165,12 @@ object Form1: TForm1 OnGetData = PythonDelphiVar1GetData OnSetData = PythonDelphiVar1SetData OnChange = PythonDelphiVar1Change - left = 136 + Left = 136 end object PythonGUIInputOutput1: TPythonGUIInputOutput UnicodeIO = True RawOutput = False Output = Memo2 - left = 40 + Left = 40 end end diff --git a/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas b/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas index 85b22e63..128d35b2 100644 --- a/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas +++ b/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas @@ -8,7 +8,7 @@ interface SysUtils, Classes, {$IFDEF MSWINDOWS} Windows, Messages, Graphics, Controls, Forms, Dialogs, - StdCtrls, ComCtrls, ExtCtrls, + StdCtrls, ComCtrls, ExtCtrls, Menus, {$ENDIF} {$IFDEF LINUX} QForms, QDialogs, QStdCtrls, QControls, QExtCtrls, @@ -249,7 +249,7 @@ procedure TForm1.PythonType1Initialization(Sender: TObject); // In the initialization of a new type, we must // define the attributes of this type PyType := TheType; - with PyType do + with PyType do begin tp_basicsize := sizeof(PyPointRec); tp_dealloc := PyPoint_dealloc; @@ -260,7 +260,7 @@ procedure TForm1.PythonType1Initialization(Sender: TObject); end; TheType := PyType; // And then add the methods of the object, if needed - AddMethod( 'OffsetBy', PyPoint_OffsetBy, 'OffsetBy(dx, dy)' ); + AddMethod( 'OffsetBy', PyPoint_OffsetBy , 'OffsetBy(dx, dy)' ); end; end; From d90c6a6e7e2a65b99ee71db33bd5c88b47e1cc69 Mon Sep 17 00:00:00 2001 From: zbyna Date: Mon, 14 May 2018 01:47:07 +0200 Subject: [PATCH 7/9] Partially fix for demo25 --- PythonForDelphi/Demos/FPC/Demo25/project1.lpi | 285 +++++++++++------- PythonForDelphi/Demos/FPC/Demo25/project1.res | Bin 138130 -> 138932 bytes PythonForDelphi/Demos/FPC/Demo25/unit1.lfm | 27 +- PythonForDelphi/Demos/FPC/Demo25/unit1.lrs | 74 ++--- PythonForDelphi/Demos/FPC/Demo25/unit1.pas | 90 +++--- 5 files changed, 282 insertions(+), 194 deletions(-) diff --git a/PythonForDelphi/Demos/FPC/Demo25/project1.lpi b/PythonForDelphi/Demos/FPC/Demo25/project1.lpi index b90ec537..ee816dc6 100644 --- a/PythonForDelphi/Demos/FPC/Demo25/project1.lpi +++ b/PythonForDelphi/Demos/FPC/Demo25/project1.lpi @@ -1,20 +1,89 @@ - + + - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -36,209 +105,206 @@ - + - - + + - - - - + + + + + - - + - + - + - + - + - + - - - - - - - + + + + + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + @@ -248,25 +314,34 @@ - - - + + + + + + + + + + + + diff --git a/PythonForDelphi/Demos/FPC/Demo25/project1.res b/PythonForDelphi/Demos/FPC/Demo25/project1.res index 708df3c5dd4b89a8cddd9168759a69bbe9c91d34..877868cb4251927ab961b2295948c0d753ecb7cd 100644 GIT binary patch delta 899 zcmaKr&ubGw6vsD%Xb>s^!KSxqM8U&kXLe@xN7zQ{A<%<*2;gn&2y1VIQM1W!HnPw?i+yZ1VqO(oX0hhe_+=FR6l-g`4!)W3YIzk^Nhs$oFG zFiuXIdeyWtj7GyS=2;W`y0)8Tk3^#8&$ocT__PIn)^0#QOp{C$aS#vUV*a%WZco=O zllCELbvLd<=!+~H#G!Ughf4$Ww-JI*>?zCPh z3lqY)g9v9fVl?DP@JJzyU8$6!l1BJ-3!2@HsSfrp+qr~GIiYUg3B;wRxltgIt1O9x z#Td3M9(hz$-2brd`Pk_)UnZ=`aur3K1|DLJ5flh7MAG&o6HM5Ox)*WVOH!7%SE?ep(Vusx-x^RaXtSM$(UMG+5Qh_J{r4u2@8K;iKf7S2w>SQ5;m>Nl fy4H)gA8Wk_r8xdkJGxVf4*(oBO7ZL_$gcbW&1waN delta 163 zcmdn8mt)d)jtL49k0vrOC@?TE{Qu7k#Ed`|1A~A7C(C99cBV;8oGi^MGqq?ig=CfBg30XdVGu%$?dGs6s)fE#Q8G>) c := a shl b; c := c shr b; - Assert( Integer(c) = Integer(a) ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = StrToIntDef(Trim(VarToStr(a)), 0) ); c := b shr 1; - Assert( Integer(c) = 1 ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = 1 ); // and c := a and (a*5); - Assert( Integer(c) = Integer(a) ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = StrToIntDef(Trim(VarToStr(a)), 0) ); c := a and 6; - Assert( Integer(c) = Integer(a) ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = StrToIntDef(Trim(VarToStr(a)), 0) ); // or c := a or b; - Assert( Integer(c) = 3 ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = 3 ); c := a or 3; - Assert( Integer(c) = 3 ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = 3 ); // xor c := a xor b; - Assert( Integer(c) = 1 ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = 1 ); c := a xor 3; - Assert( Integer(c) = 1 ); + Assert( StrToIntDef(Trim(VarToStr(c)), 0) = 1 ); // comparisons //------------ From 8035a2c378f814cee1b8290dc8c027935c29fde4 Mon Sep 17 00:00:00 2001 From: zbyna Date: Mon, 14 May 2018 01:47:30 +0200 Subject: [PATCH 8/9] Partially fix for demo31 --- PythonForDelphi/Demos/FPC/Demo31/Project1.lpi | 29 ++----- PythonForDelphi/Demos/FPC/Demo31/Project1.res | Bin 855 -> 1657 bytes PythonForDelphi/Demos/FPC/Demo31/Unit1.lfm | 81 +++++++++--------- PythonForDelphi/Demos/FPC/Demo31/Unit2.lfm | 21 +++-- 4 files changed, 63 insertions(+), 68 deletions(-) diff --git a/PythonForDelphi/Demos/FPC/Demo31/Project1.lpi b/PythonForDelphi/Demos/FPC/Demo31/Project1.lpi index 9645cf5e..6cda066e 100644 --- a/PythonForDelphi/Demos/FPC/Demo31/Project1.lpi +++ b/PythonForDelphi/Demos/FPC/Demo31/Project1.lpi @@ -1,7 +1,7 @@ - + @@ -15,9 +15,6 @@ - - - @@ -46,7 +43,7 @@ - + @@ -56,9 +53,10 @@ - - - + + + + @@ -69,17 +67,16 @@ - + - + - @@ -95,7 +92,6 @@ - @@ -104,9 +100,7 @@ - - @@ -135,7 +129,6 @@ - @@ -144,7 +137,6 @@ - @@ -161,7 +153,6 @@ - @@ -185,9 +176,7 @@ - - @@ -238,8 +227,6 @@ - - diff --git a/PythonForDelphi/Demos/FPC/Demo31/Project1.res b/PythonForDelphi/Demos/FPC/Demo31/Project1.res index e66ecf85feb5a99d4bc85c4973bd1bb2e918b668..bc23f8c77ed575e1c5a54800e9b3941dbf133309 100644 GIT binary patch literal 1657 zcma)6O^@3)5ZzvSC{Q5B9vL1BP~VcJg}i|gB!JQ81K2b{j}$rD6)KS`NqJ)w{q4!f zlD*ns*NFjHB8PmO_vUdfE-o$zK3~2}4}L!Q6+a*2zu}sn4zXv??w6D=K6fqIfw7HN zYZ`h1C7^_sjk;OWzdpQXIVIL{C3&kAtmz&seR1{cFD17Yx~kn11W6Qyj@61$5m5lKRei$feVY zz0}GX-CBAtM>dLaUXFgKki;Lb|DgW?ENPY&X_X~mk_b_UvZkcv>So|K2lWn0kdfdc z1n#FNo~1K`bz4>IA1r!ICwVN0!C+lyRSf()pbtR4H_fhT;Rfs!A>}Fb>ND;cEAc1n zpe612zoy)7)edr8bH>PASMssJn?x9!Lw4wUZBT}H*JLZ#^goD#Fig@F3)3WHNi0&v z(;8S1z1~yK^IIjxMQduBuT}hThBpHvAB#5H4E@J)!Y<>nd z;ZYss5VJI{3YH{E$SPh4CbL2&JmDF{`BSi7cm_DEvsETm8Os9*SrWwsLkm|dk7ZD2 zGLU@r6mS@v!ObD4S3HbZRaY_U069ZdQkLYkOamUKyjbese_PDbe^B**R# z$vR`t+r{5)ipTpgpS)x&K3>o;3J3WC(1J$BqY o`4Jma-)!!$(N8QcPR&iqsk8$C DfzA*K diff --git a/PythonForDelphi/Demos/FPC/Demo31/Unit1.lfm b/PythonForDelphi/Demos/FPC/Demo31/Unit1.lfm index c8223e84..2c34cee3 100644 --- a/PythonForDelphi/Demos/FPC/Demo31/Unit1.lfm +++ b/PythonForDelphi/Demos/FPC/Demo31/Unit1.lfm @@ -2,19 +2,19 @@ object Form1: TForm1 Left = 659 Height = 647 Top = 47 - Width = 685 + Width = 668 VertScrollBar.Range = 210 ActiveControl = Memo1 Caption = 'Form1' ClientHeight = 647 ClientWidth = 668 Color = clBtnFace + DesignTimePPI = 134 Font.Color = clWindowText Font.Height = 11 Font.Name = 'MS Sans Serif' Font.Pitch = fpVariable OnCreate = FormCreate - LCLVersion = '0.9.30.2' Visible = True object Splitter1: TSplitter Cursor = crVSplit @@ -66,7 +66,7 @@ object Form1: TForm1 ' self.Height = 400' '' ' def btnCloseClick(self, Sender):' - ' print "Close!"' + ' print("Close!")' ' self.Close()' '' ' def MyFormCloseQuery(self, Sender, CanClose):' @@ -78,7 +78,7 @@ object Form1: TForm1 ' def grdTestDrawCell(self, Sender, Col, Row, Rect, State):' ' if gdSelected in State:' ' Sender.Canvas.Brush.Color = clBlue # 0x00ff0000 # blue' - ' print "Cell[%d, %d] is selected, Rect=%s, State=%s" % (Col, Row, Rect, State)' + ' print ("Cell[%d, %d] is selected, Rect=%s, State=%s" % (Col, Row, Rect, State))' ' Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d @ %d" % (Col, Row))' '' ' def grdTestSelectCell(self, Sender, Col, Row, CanSelect):' @@ -102,8 +102,8 @@ object Form1: TForm1 ' self.assertEqual(DVar.IValue, 70)' ' MainForm.Caption = ''PyDelphi rocks!'' #setting properties' ' self.assertEqual(MainForm.Caption, ''PyDelphi rocks!'')' - ' print' - ' print ''MainForm.ActiveControl='', MainForm.ActiveControl # class properties' + ' print()' + ' print( ''MainForm.ActiveControl='', MainForm.ActiveControl) # class properties' ' MainForm.BorderStyle = ''bsSizeable'' #enumeration property' ' MainForm.Anchors = [''akTop'', ''akLeft''] #set property' ' self.assertEqual(MainForm.Anchors, [''akTop'', ''akLeft''])' @@ -117,23 +117,23 @@ object Form1: TForm1 ' DVar.SetMeUp(''Age'', 25)' ' self.assertEqual(DVar.SValue, ''Age'')' ' self.assertEqual(DVar.IValue, 25)' - ' print' - ' print DVar.DescribeMe() #method calls' + ' print()' + ' print( DVar.DescribeMe()) #method calls' '' ' def testRepr(self):' - ' print' - ' print ''Representation of Delphi objects''' - ' print DVar' - ' print MainForm' + ' print()' + ' print (''Representation of Delphi objects'')' + ' print (DVar)' + ' print (MainForm)' ' if DelphiVersion >= 7:' - ' print DVar.DescribeMe # method object' - ' print DVar.SL # TStrings' + ' print (DVar.DescribeMe) # method object' + ' print (DVar.SL) # TStrings' '' ' def testTStrings(self):' ' SL = DVar.SL' ' self.assertEqual(len(SL), 2)' - ' print' - ' for i in DVar.SL: print i, '' contains '', DVar.SL[i]' + ' print()' + ' for i in DVar.SL: print (i), '' contains '', DVar.SL[i]' ' SL.Add(''New String'')' ' self.assertEqual(len(SL), 3)' ' self.assertEqual(SL.IndexOf(''New String''), 2)' @@ -148,7 +148,7 @@ object Form1: TForm1 ' self.assertEqual(MainForm in SL.Objects, True)' ' SL.Delete(2)' ' self.assertEqual(len(SL), 2)' - ' print "str(SL) =", str(SL)' + ' print ("str(SL) =", str(SL))' ' SL.Assign([1, 2, 3])' ' self.assertEqual(len(SL), 3)' ' self.assertEqual(''2'' in SL, True)' @@ -180,7 +180,7 @@ object Form1: TForm1 ' self.assertEqual(MainForm.Button1.Caption, ''Click me!!!!'')' ' # Test Owner property and DelphiObject comparison' ' self.assert_(MainForm.Button1.Owner == MainForm)' - ' print [i.Name for i in MainForm.Components]' + ' print ([i.Name for i in MainForm.Components])' '' ' def testCreateComponent(self):' ' NewButton = CreateComponent(''TButton'', None)' @@ -191,9 +191,9 @@ object Form1: TForm1 '' ' def testWinControls(self):' ' self.assertEqual(MainForm.Panel1.Parent, MainForm)' - ' print' - ' print ''MainForm contains '', MainForm.ControlCount, '' controls''' - ' print [i.Name for i in MainForm.Controls]' + ' print()' + ' print (''MainForm contains '', MainForm.ControlCount, '' controls'')' + ' print ([i.Name for i in MainForm.Controls])' '' ' def testForm(self):' ' MyForm = CreateComponent(''TForm'', None)' @@ -246,7 +246,7 @@ object Form1: TForm1 ' B2.ModalResult = mrOk' ' B2.TabOrder = 3' ' def ClickHandler(Sender):' - ' print Sender.Name, '' was clicked''' + ' print (Sender.Name, '' was clicked'')' ' LB.Items.Add(Edit.Text)' ' B1.OnClick = ClickHandler' ' def KeyPressHandler(Sender, Key):' @@ -302,21 +302,21 @@ object Form1: TForm1 ' def testFormSubclass(self):' ' f = MyForm(Application)' ' try:' - ' print f.ShowModal()' + ' print (f.ShowModal())' ' finally:' ' f.Free()' '' ' def testFormSubclass2(self):' ' f = TTestForm(Application)' ' try:' - ' print f.ShowModal()' + ' print (f.ShowModal())' ' finally:' ' f.Free()' '' ' def testPointConversions(self):' ' p1 = Point(10, 10)' ' p = MainForm.ClientToScreen(p1)' - ' print p' + ' print (p)' ' p2 = MainForm.ScreenToClient(p)' ' self.assertEqual(p2.X, p1.X)' ' self.assertEqual(p2.Y, p1.Y)' @@ -324,7 +324,7 @@ object Form1: TForm1 ' def testObjectNotification(self):' ' DVar.IValue = 0' ' def ChangeHandler(Sender):' - ' print Sender' + ' print (Sender)' ' Sender.IValue = 55' ' DVar.OnChange = ChangeHandler' ' if DelphiVersion >= 7:' @@ -343,7 +343,7 @@ object Form1: TForm1 ' MainForm.actTest.Execute()' ' self.assertEqual(DVar.IValue, 1)' ' def ActionHandler(Sender):' - ' print "Action", Sender.Name, "executed from Python"' + ' print ("Action", Sender.Name, "executed from Python")' ' DVar.IValue = 2' ' self.assertEqual(MainForm.actTest.OnExecute, None)' ' MainForm.actTest.OnExecute = ActionHandler' @@ -371,8 +371,8 @@ object Form1: TForm1 ' MainForm.Button1.SetFocus()' ' self.assertEqual(Screen.ActiveControl, MainForm.Button1)' ' def ActiveControlChangeHandler(Sender):' - ' print "ActiveControlChangeHandler fired"' - ' print "New active constrol is", Sender.ActiveControl.Name' + ' print ("ActiveControlChangeHandler fired")' + ' print ("New active constrol is", Sender.ActiveControl.Name)' ' DVar.IValue = 2' ' self.assertEqual(Screen.OnActiveControlChange, None)' ' Screen.OnActiveControlChange = ActiveControlChangeHandler' @@ -402,10 +402,8 @@ object Form1: TForm1 ' except SystemExit:' ' pass' ' MainForm.ActiveControl = MainForm.Memo2 # Class property!' - '' - ' ' - ' ' ) + ParentFont = False ScrollBars = ssVertical TabOrder = 0 end @@ -418,6 +416,7 @@ object Form1: TForm1 BevelOuter = bvNone ClientHeight = 41 ClientWidth = 668 + ParentFont = False TabOrder = 1 object Button1: TButton Left = 8 @@ -426,6 +425,7 @@ object Form1: TForm1 Width = 75 Caption = 'Execute' OnClick = Button1Click + ParentFont = False TabOrder = 0 end end @@ -435,13 +435,14 @@ object Form1: TForm1 Top = 0 Width = 668 Align = alTop + ParentFont = False ScrollBars = ssBoth TabOrder = 2 end object PyEngine: TPythonEngine IO = PythonGUIInputOutput1 - left = 16 - top = 16 + Left = 16 + Top = 16 end object PythonModule: TPythonModule Engine = PyEngine @@ -455,19 +456,19 @@ object Form1: TForm1 end> ModuleName = 'spam' Errors = <> - left = 56 - top = 16 + Left = 56 + Top = 16 end object PythonGUIInputOutput1: TPythonGUIInputOutput UnicodeIO = False RawOutput = False Output = Memo2 - left = 168 - top = 17 + Left = 168 + Top = 17 end object ActionList1: TActionList - left = 96 - top = 80 + Left = 96 + Top = 80 object actTest: TAction Caption = 'Test' OnExecute = actTestExecute diff --git a/PythonForDelphi/Demos/FPC/Demo31/Unit2.lfm b/PythonForDelphi/Demos/FPC/Demo31/Unit2.lfm index 75d6772b..76dbe787 100644 --- a/PythonForDelphi/Demos/FPC/Demo31/Unit2.lfm +++ b/PythonForDelphi/Demos/FPC/Demo31/Unit2.lfm @@ -3,24 +3,28 @@ object TestForm: TTestForm Height = 341 Top = 200 Width = 614 + ActiveControl = CheckBox1 ClientHeight = 341 ClientWidth = 614 - LCLVersion = '1.5' + DesignTimePPI = 134 + Visible = False object CheckBox1: TCheckBox Left = 96 - Height = 22 + Height = 24 Top = 16 - Width = 91 + Width = 96 Caption = 'CheckBox1' + ParentFont = False TabOrder = 0 end object CheckBox2: TCheckBox Left = 96 - Height = 22 + Height = 24 Top = 56 - Width = 91 + Width = 96 Caption = 'CheckBox2' Checked = True + ParentFont = False State = cbChecked TabOrder = 1 end @@ -31,13 +35,15 @@ object TestForm: TTestForm Width = 75 Caption = 'Close' OnClick = btnCloseClick + ParentFont = False TabOrder = 2 end object Edit1: TEdit Left = 96 - Height = 25 + Height = 28 Top = 96 Width = 121 + ParentFont = False TabOrder = 3 Text = 'Edit1' end @@ -47,9 +53,9 @@ object TestForm: TTestForm Top = 48 Width = 249 ItemHeight = 0 + ParentFont = False ScrollWidth = 247 TabOrder = 4 - TopIndex = -1 end object btnAdd: TButton Left = 104 @@ -57,6 +63,7 @@ object TestForm: TTestForm Top = 128 Width = 75 Caption = 'Add' + ParentFont = False TabOrder = 5 end end From 3d8936a95e8e805b1a269d58ff55993c8d4f1569 Mon Sep 17 00:00:00 2001 From: zbyna Date: Tue, 15 May 2018 06:20:40 +0200 Subject: [PATCH 9/9] Fix demo 6 for Python 3 - python code works but remains memory leaks --- PythonForDelphi/Demos/FPC/Demo06/Unit1.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas b/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas index 128d35b2..0ce458a5 100644 --- a/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas +++ b/PythonForDelphi/Demos/FPC/Demo06/Unit1.pas @@ -173,9 +173,10 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl; else begin // Else check for a method - Result := Py_FindMethod( MethodsByName('PythonType1'), obj, key); + Result:=PyObject_GenericGetAttr(obj,PyString_FromString('OffsetBy')); + //Result := Py_FindMethod( MethodsByName('PythonType1'), obj, key); // or we could write, because it's quicker: - // Result := Py_FindMethod( Form1.PythonType1.MethodsData, obj, key); + //Result := Py_FindMethod( Form1.PythonType1.MethodsData, obj, key); if not Assigned(Result) then PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Format('Unknown attribute "%s"',[key]))); end; @@ -261,6 +262,7 @@ procedure TForm1.PythonType1Initialization(Sender: TObject); TheType := PyType; // And then add the methods of the object, if needed AddMethod( 'OffsetBy', PyPoint_OffsetBy , 'OffsetBy(dx, dy)' ); + PythonEngine1.PyType_Ready(TheTypePtr); end; end;