Skip to content

Commit c8edaa5

Browse files
committed
Added CreateWith overload for backward compatibility as in the Embarcadero fork
Reversed earlier changes. Where CreateWith is overwritten use the simpler version of CreateWith Fixed TPythonType.AddTypeVar (METH_KEYWORDS needs to be combined with METH_VARARGS) Fixed Demo28
1 parent 958d87d commit c8edaa5

File tree

12 files changed

+770
-880
lines changed

12 files changed

+770
-880
lines changed

Demos/Demo08/Unit1.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TPyPoint = class(TPyObject)
3838

3939
// Constructors & Destructors
4040
constructor Create( APythonType : TPythonType ); override;
41-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
41+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
4242

4343
// Type services
4444
////////////////
@@ -88,7 +88,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
8888
// the Create constructor first, and because the constructors
8989
// are virtual, TPyPoint.Create will be automatically be called.
9090

91-
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
91+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args: PPyObject);
9292
begin
9393
inherited;
9494
with GetPythonEngine do

Demos/Demo21/Unit1.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ TPyPoint = class(TPyObject)
4646

4747
// Constructors & Destructors
4848
constructor Create( APythonType : TPythonType ); override;
49-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject ); override;
49+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
5050

5151
// Type services
5252
////////////////
@@ -81,7 +81,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
8181
// the Create constructor first, and because the constructors
8282
// are virtual, TPyPoint.Create will be automatically be called.
8383

84-
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
84+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args: PPyObject);
8585
begin
8686
inherited;
8787
with GetPythonEngine do

Demos/Demo26/Unit1.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ TPyPoint = class(TPyObject)
3535

3636
// Constructors & Destructors
3737
constructor Create( APythonType : TPythonType ); override;
38-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
38+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
3939

4040
// Type services
4141
////////////////
@@ -84,7 +84,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
8484
// the Create constructor first, and because the constructors
8585
// are virtual, TPyPoint.Create will be automatically be called.
8686

87-
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
87+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args: PPyObject);
8888
begin
8989
inherited;
9090
with GetPythonEngine do

Demos/Demo28/Unit1.pas

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ TPyStringList = class(TPyObject)
1818
public
1919
// Constructors & Destructors
2020
constructor Create( APythonType : TPythonType ); override;
21-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
21+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
2222
destructor Destroy; override;
2323

2424
// Basic services
@@ -46,7 +46,7 @@ TPyStringListIterator = class(TPyObject)
4646
procedure SetStringList(const Value: TPyStringList);
4747
public
4848
constructor Create( APythonType : TPythonType ); override;
49-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
49+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
5050
destructor Destroy; override;
5151

5252
// Basic services
@@ -145,8 +145,7 @@ constructor TPyStringList.Create(APythonType: TPythonType);
145145
fStrings := TStringList.Create;
146146
end;
147147

148-
constructor TPyStringList.CreateWith(PythonType: TPythonType; args, kwds:
149-
PPyObject);
148+
constructor TPyStringList.CreateWith(PythonType: TPythonType; args: PPyObject);
150149
var
151150
i : Integer;
152151
begin
@@ -170,12 +169,15 @@ function TPyStringList.Iter: PPyObject;
170169
var
171170
// _iter : TPyStringListIterator;
172171
_args : PPyObject;
172+
_kwrds: PPyObject;
173173
begin
174174
_args := GetPythonEngine.MakePyTuple([Self.GetSelf]);
175+
_kwrds := GetPythonEngine.PyDict_New;
175176
try
176-
Result := Form1.ptStringListIterator.CreateInstanceWith(_args);
177+
Result := Form1.ptStringListIterator.CreateInstanceWith(_args, _kwrds);
177178
finally
178179
GetPythonEngine.Py_DECREF(_args);
180+
GetPythonEngine.Py_DECREF(_kwrds);
179181
end;
180182
{_iter := Form1.ptStringListIterator.CreateInstance as TPyStringListIterator;
181183
_iter.StringList := Self;
@@ -239,8 +241,7 @@ constructor TPyStringListIterator.Create(APythonType: TPythonType);
239241
inherited;
240242
end;
241243

242-
constructor TPyStringListIterator.CreateWith(PythonType: TPythonType; args,
243-
kwds: PPyObject);
244+
constructor TPyStringListIterator.CreateWith(PythonType: TPythonType; args: PPyObject);
244245
var
245246
_obj : PPyObject;
246247
_stringList : TPyStringList;

Demos/Demo34/Unit1.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TPyPoint = class(TPyObject)
4343

4444
// Constructors & Destructors
4545
constructor Create( APythonType : TPythonType ); override;
46-
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
46+
constructor CreateWith(PythonType: TPythonType; args: PPyObject); override;
4747

4848
// Type services
4949
////////////////
@@ -158,7 +158,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
158158
// the Create constructor first, and because the constructors
159159
// are virtual, TPyPoint.Create will automatically be called.
160160

161-
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
161+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args: PPyObject);
162162
begin
163163
inherited;
164164
with GetPythonEngine do

Source/PythonEngine.pas

+16-11
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,7 @@ TPythonModule = class(TMethodsContainer)
23632363
- Properties ob_refcnt and ob_type will call GetSelf to access their data.
23642364
}
23652365
// The base class of all new Python types
2366+
TPyObjectClass = class of TPyObject;
23662367
TPyObject = class
23672368
private
23682369
function Get_ob_refcnt: NativeInt;
@@ -2375,9 +2376,9 @@ TPyObject = class
23752376
PythonAlloc : Boolean;
23762377

23772378
// Constructors & Destructors
2378-
constructor Create( APythonType : TPythonType ); virtual;
2379-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject);
2380-
virtual;
2379+
constructor Create(APythonType: TPythonType); virtual;
2380+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); overload; virtual;
2381+
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); overload; virtual;
23812382
destructor Destroy; override;
23822383

23832384
class function NewInstance: TObject; override;
@@ -2469,7 +2470,6 @@ TPyObject = class
24692470
class procedure RegisterGetSets( APythonType : TPythonType ); virtual;
24702471
class procedure SetupType( APythonType : TPythonType ); virtual;
24712472
end;
2472-
TPyObjectClass = class of TPyObject;
24732473

24742474
TBasicServices = set of (bsGetAttr, bsSetAttr,
24752475
bsRepr, bsCompare, bsHash,
@@ -2680,7 +2680,7 @@ TPyVar = class(TPyObject)
26802680

26812681
// Constructors & Destructors
26822682
constructor Create( APythonType : TPythonType ); override;
2683-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
2683+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
26842684
destructor Destroy; override;
26852685

26862686
// Type services
@@ -7385,7 +7385,7 @@ function TPythonModule.GetVarAsVariant( const varName : AnsiString ) : Variant;
73857385
// TPyObject
73867386

73877387
// Constructors & Destructors
7388-
constructor TPyObject.Create( APythonType : TPythonType );
7388+
constructor TPyObject.Create(APythonType: TPythonType);
73897389
begin
73907390
inherited Create;
73917391
if Assigned(APythonType) then
@@ -7400,10 +7400,15 @@ constructor TPyObject.Create( APythonType : TPythonType );
74007400
end;
74017401
end;
74027402

7403-
constructor TPyObject.CreateWith(APythonType: TPythonType; args, kwds:
7404-
PPyObject);
7403+
constructor TPyObject.CreateWith(APythonType: TPythonType; args: PPyObject);
7404+
begin
7405+
Create(APythonType);
7406+
end;
7407+
7408+
constructor TPyObject.CreateWith(APythonType: TPythonType; args,
7409+
kwds: PPyObject);
74057410
begin
7406-
Create( APythonType );
7411+
CreateWith(APythonType, args);
74077412
end;
74087413

74097414
destructor TPyObject.Destroy;
@@ -8649,7 +8654,7 @@ procedure TPythonType.AddTypeVar;
86498654
meth := CreateMethod;
86508655
FCreateFuncDef.ml_name := PAnsiChar(FCreateFuncName);
86518656
FCreateFuncDef.ml_meth := GetOfObjectCallBack(TCallBack(meth), 3, DEFAULT_CALLBACK_TYPE);
8652-
FCreateFuncDef.ml_flags := METH_KEYWORDS;
8657+
FCreateFuncDef.ml_flags := METH_VARARGS or METH_KEYWORDS;
86538658
FCreateFuncDef.ml_doc := PAnsiChar(FCreateFuncDoc);
86548659
FCreateFunc := Engine.PyCFunction_NewEx(@FCreateFuncDef, nil, nil);
86558660
Engine.Py_INCREF(FCreateFunc);
@@ -8888,7 +8893,7 @@ constructor TPyVar.Create( APythonType : TPythonType );
88888893
// the Create constructor first, and because the constructors
88898894
// are virtual, TPyVar.Create will be automatically be called.
88908895

8891-
constructor TPyVar.CreateWith(APythonType: TPythonType; args, kwds: PPyObject);
8896+
constructor TPyVar.CreateWith(APythonType: TPythonType; args: PPyObject);
88928897
begin
88938898
inherited;
88948899
with GetPythonEngine do

Source/WrapDelphiTypes.pas

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TPyDelphiPoint = class(TPyObject)
2323
function Set_X(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
2424
function Set_Y(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
2525
public
26-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
26+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
2727

2828
function Compare( obj: PPyObject) : Integer; override;
2929
function Repr : PPyObject; override;
@@ -55,7 +55,7 @@ TPyDelphiRect = class(TPyObject)
5555
public
5656
PyDelphiWrapper : TPyDelphiWrapper;
5757

58-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
58+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
5959

6060
function Compare( obj: PPyObject) : Integer; override;
6161
function Repr : PPyObject; override;
@@ -77,7 +77,7 @@ TPyDelphiSize = class(TPyObject)
7777
function Set_CX(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
7878
function Set_CY(AValue : PPyObject; AContext : Pointer) : Integer; cdecl;
7979
public
80-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
80+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
8181

8282
function Compare( obj: PPyObject) : Integer; override;
8383
function Repr : PPyObject; override;
@@ -235,7 +235,7 @@ function TPyDelphiPoint.Compare(obj: PPyObject): Integer;
235235
Result := 1;
236236
end;
237237

238-
constructor TPyDelphiPoint.CreateWith(APythonType: TPythonType; args, kwds:
238+
constructor TPyDelphiPoint.CreateWith(APythonType: TPythonType; args:
239239
PPyObject);
240240
var
241241
x, y : Integer;
@@ -340,8 +340,7 @@ function TPyDelphiRect.Compare(obj: PPyObject): Integer;
340340
Result := 1;
341341
end;
342342

343-
constructor TPyDelphiRect.CreateWith(APythonType: TPythonType; args, kwds:
344-
PPyObject);
343+
constructor TPyDelphiRect.CreateWith(APythonType: TPythonType; args: PPyObject);
345344
begin
346345
inherited;
347346
APythonType.Engine.PyArg_ParseTuple( args, 'iiii:Create',@fValue.Left, @fValue.Top, @fValue.Right, @fValue.Bottom );
@@ -528,8 +527,7 @@ function TPyDelphiSize.Compare(obj: PPyObject): Integer;
528527
Result := 1;
529528
end;
530529

531-
constructor TPyDelphiSize.CreateWith(APythonType: TPythonType; args, kwds:
532-
PPyObject);
530+
constructor TPyDelphiSize.CreateWith(APythonType: TPythonType; args: PPyObject);
533531
var
534532
cx, cy : Integer;
535533
begin

Source/fmx/WrapFmxStyles.pas

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TPyDelphiStyleStreaming = class(TPyDelphiObject)
1313
procedure SetDelphiObject(const Value: TStyleStreaming);
1414
public
1515
constructor Create( APythonType : TPythonType ); override;
16-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
16+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
1717
class function DelphiObjectClass : TClass; override;
1818
class procedure RegisterGetSets(PythonType: TPythonType); override;
1919
class procedure RegisterMethods(PythonType: TPythonType); override;
@@ -72,8 +72,7 @@ constructor TPyDelphiStyleStreaming.Create(APythonType: TPythonType);
7272
inherited;
7373
end;
7474

75-
constructor TPyDelphiStyleStreaming.CreateWith(APythonType: TPythonType; args,
76-
kwds: PPyObject);
75+
constructor TPyDelphiStyleStreaming.CreateWith(APythonType: TPythonType; args: PPyObject);
7776
begin
7877
inherited;
7978
DelphiObject := TStyleStreaming.Create();

Source/fmx/WrapFmxTypes.pas

+13-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TPyDelphiPointF = class(TPyObject)
2222
function Set_X(AValue: PPyObject; AContext: Pointer): integer; cdecl;
2323
function Set_Y(AValue: PPyObject; AContext: Pointer): integer; cdecl;
2424
public
25-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
25+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
2626
function Compare(obj: PPyObject): Integer; override;
2727
function Repr: PPyObject; override;
2828
class procedure RegisterGetSets(PythonType: TPythonType); override;
@@ -41,7 +41,7 @@ TPyDelphiSizeF = class(TPyObject)
4141
function Set_Width(AValue: PPyObject; AContext: Pointer): integer; cdecl;
4242
function Set_Height(AValue: PPyObject; AContext: Pointer): integer; cdecl;
4343
public
44-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
44+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
4545
function Compare(obj: PPyObject): Integer; override;
4646
function Repr: PPyObject; override;
4747
class procedure RegisterGetSets(PythonType: TPythonType); override;
@@ -64,7 +64,7 @@ TPyDelphiRectF = class(TPyObject)
6464
function Set_Left(AValue: PPyObject; AContext: Pointer): integer; cdecl;
6565
function Set_Right(AValue: PPyObject; AContext: Pointer): integer; cdecl;
6666
public
67-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
67+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
6868
function Compare(obj: PPyObject): Integer; override;
6969
function Repr: PPyObject; override;
7070
class procedure RegisterGetSets(PythonType: TPythonType); override;
@@ -103,7 +103,7 @@ TPyDelphiPosition = class(TPyDelphiPersistent)
103103
function Set_Y(AValue: PPyObject; AContext: Pointer): integer; cdecl;
104104
function Set_Point(AValue: PPyObject; AContext: Pointer): integer; cdecl;
105105
public
106-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
106+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
107107
class function DelphiObjectClass: TClass; override;
108108
class procedure RegisterMethods(PythonType: TPythonType); override;
109109
class procedure RegisterGetSets(PythonType: TPythonType); override;
@@ -128,7 +128,7 @@ TPyDelphiBounds = class(TPyDelphiPersistent)
128128
function Get_Rect(Acontext: Pointer): PPyObject; cdecl;
129129
function Set_Rect(AValue: PPyObject; AContext: Pointer): integer; cdecl;
130130
public
131-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
131+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
132132
class function DelphiObjectClass: TClass; override;
133133
class procedure RegisterGetSets(PythonType: TPythonType); override;
134134
property DelphiObject: TBounds read GetDelphiObject write SetDelphiObject;
@@ -142,7 +142,7 @@ TPyDelphiControlSize = class(TPyDelphiPersistent)
142142
function Get_SizeF(Acontext: Pointer): PPyObject; cdecl;
143143
function Set_SizeF(AValue: PPyObject; AContext: Pointer): integer; cdecl;
144144
public
145-
constructor CreateWith(APythonType: TPythonType; args, kwds: PPyObject); override;
145+
constructor CreateWith(APythonType: TPythonType; args: PPyObject); override;
146146
class function DelphiObjectClass: TClass; override;
147147
class procedure RegisterGetSets(PythonType: TPythonType); override;
148148
property DelphiObject: TControlSize read GetDelphiObject write SetDelphiObject;
@@ -184,7 +184,7 @@ function TPyDelphiPointF.Compare(obj: PPyObject): Integer;
184184
Result := 1;
185185
end;
186186

187-
constructor TPyDelphiPointF.CreateWith(APythonType: TPythonType; args, kwds:
187+
constructor TPyDelphiPointF.CreateWith(APythonType: TPythonType; args:
188188
PPyObject);
189189
var
190190
x, y : single;
@@ -424,7 +424,7 @@ function TPyDelphiFmxObject.Set_Parent(AValue: PPyObject;
424424
end;
425425

426426
{ TPyDelphiPosition }
427-
constructor TPyDelphiPosition.CreateWith(APythonType: TPythonType; args, kwds:
427+
constructor TPyDelphiPosition.CreateWith(APythonType: TPythonType; args:
428428
PPyObject);
429429
var
430430
LPPosition: PPyObject;
@@ -544,7 +544,7 @@ function TPyDelphiSizeF.Compare(obj: PPyObject): Integer;
544544
Result := 1;
545545
end;
546546

547-
constructor TPyDelphiSizeF.CreateWith(APythonType: TPythonType; args, kwds:
547+
constructor TPyDelphiSizeF.CreateWith(APythonType: TPythonType; args:
548548
PPyObject);
549549
var
550550
LWidth, LHeight : single;
@@ -646,7 +646,7 @@ procedure TPyDelphiCustomPopupMenu.SetDelphiObject(
646646
end;
647647

648648
{ TPyDelphiBounds }
649-
constructor TPyDelphiBounds.CreateWith(APythonType: TPythonType; args, kwds:
649+
constructor TPyDelphiBounds.CreateWith(APythonType: TPythonType; args:
650650
PPyObject);
651651
var
652652
LPBounds: PPyObject;
@@ -703,8 +703,8 @@ function TPyDelphiBounds.Set_Rect(AValue: PPyObject;
703703
end;
704704

705705
{ TPyDelphiControlSize }
706-
constructor TPyDelphiControlSize.CreateWith(APythonType: TPythonType; args,
707-
kwds: PPyObject);
706+
constructor TPyDelphiControlSize.CreateWith(APythonType: TPythonType; args:
707+
PPyObject);
708708
var
709709
LPControlSize: PPyObject;
710710
LSizeF: TSizeF;
@@ -775,7 +775,7 @@ function TPyDelphiRectF.Compare(obj: PPyObject): Integer;
775775
Result := 1;
776776
end;
777777

778-
constructor TPyDelphiRectF.CreateWith(APythonType: TPythonType; args, kwds:
778+
constructor TPyDelphiRectF.CreateWith(APythonType: TPythonType; args:
779779
PPyObject);
780780
var
781781
LLeft, LTop, LRight, LBottom : single;

0 commit comments

Comments
 (0)