Skip to content

Commit 0a50d19

Browse files
committed
Demo 32 updated to show off the use of keyword arguments
1 parent d842a47 commit 0a50d19

20 files changed

+107
-104
lines changed

Demos/Demo08/Unit1.dfm

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
17-
PixelsPerInch = 96
1816
TextHeight = 13
1917
object Splitter1: TSplitter
2018
Left = 0

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 : PPyObject ); override;
41+
constructor CreateWith(PythonType: TPythonType; args, kwds: 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 : PPyObject );
91+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
9292
begin
9393
inherited;
9494
with GetPythonEngine do

Demos/Demo21/Unit1.dfm

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ object Form1: TForm1
1010
Font.Height = -11
1111
Font.Name = 'MS Sans Serif'
1212
Font.Style = []
13-
OldCreateOrder = True
14-
PixelsPerInch = 96
1513
TextHeight = 13
1614
object Splitter1: TSplitter
1715
Left = 0
@@ -20,8 +18,6 @@ object Form1: TForm1
2018
Height = 3
2119
Cursor = crVSplit
2220
Align = alTop
23-
ExplicitTop = 153
24-
ExplicitWidth = 536
2521
end
2622
object Memo1: TMemo
2723
Left = 0
@@ -145,7 +141,7 @@ object Form1: TForm1
145141
TypeName = 'Point'
146142
Prefix = 'Create'
147143
Module = PythonModule1
148-
Services.Basic = [bsGetAttrO, bsSetAttrO, bsRepr, bsStr]
144+
Services.Basic = [bsRepr, bsStr, bsGetAttrO, bsSetAttrO]
149145
Services.InplaceNumber = []
150146
Services.Number = []
151147
Services.Sequence = []

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 : PPyObject ); override;
49+
constructor CreateWith(PythonType: TPythonType; args, kwds: 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 : PPyObject );
84+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
8585
begin
8686
inherited;
8787
with GetPythonEngine do

Demos/Demo26/Unit1.dfm

-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
17-
PixelsPerInch = 96
1816
TextHeight = 13
1917
object Splitter1: TSplitter
2018
Left = 0
@@ -23,7 +21,6 @@ object Form1: TForm1
2321
Height = 3
2422
Cursor = crVSplit
2523
Align = alTop
26-
ExplicitWidth = 584
2724
end
2825
object Memo1: TMemo
2926
Left = 0

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 : PPyObject ); override;
38+
constructor CreateWith(PythonType: TPythonType; args, kwds: 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 : PPyObject );
87+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
8888
begin
8989
inherited;
9090
with GetPythonEngine do

Demos/Demo28/Unit1.dfm

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
17-
PixelsPerInch = 96
1816
TextHeight = 13
1917
object Splitter1: TSplitter
2018
Left = 0
@@ -25,7 +23,6 @@ object Form1: TForm1
2523
Align = alTop
2624
Color = clBtnFace
2725
ParentColor = False
28-
ExplicitWidth = 589
2926
end
3027
object Memo1: TMemo
3128
Left = 0
@@ -142,7 +139,7 @@ object Form1: TForm1
142139
TypeName = 'TStringList'
143140
Prefix = 'Create'
144141
Module = pmP4D
145-
Services.Basic = [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsIter]
142+
Services.Basic = [bsRepr, bsStr, bsGetAttrO, bsSetAttrO, bsIter]
146143
Services.InplaceNumber = []
147144
Services.Number = []
148145
Services.Sequence = [ssLength, ssItem, ssAssItem]
@@ -163,7 +160,7 @@ object Form1: TForm1
163160
TypeName = 'TStringListIterator'
164161
Prefix = 'Create'
165162
Module = pmP4D
166-
Services.Basic = [bsGetAttrO, bsSetAttrO, bsRepr, bsStr, bsIter, bsIterNext]
163+
Services.Basic = [bsRepr, bsStr, bsGetAttrO, bsSetAttrO, bsIter, bsIterNext]
167164
Services.InplaceNumber = []
168165
Services.Number = []
169166
Services.Sequence = []

Demos/Demo28/Unit1.pas

+6-6
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 : PPyObject ); override;
21+
constructor CreateWith(PythonType: TPythonType; args, kwds: 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 : PPyObject ); override;
49+
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
5050
destructor Destroy; override;
5151

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

148-
constructor TPyStringList.CreateWith(PythonType: TPythonType;
149-
args: PPyObject);
148+
constructor TPyStringList.CreateWith(PythonType: TPythonType; args, kwds:
149+
PPyObject);
150150
var
151151
i : Integer;
152152
begin
@@ -239,8 +239,8 @@ constructor TPyStringListIterator.Create(APythonType: TPythonType);
239239
inherited;
240240
end;
241241

242-
constructor TPyStringListIterator.CreateWith(PythonType: TPythonType;
243-
args: PPyObject);
242+
constructor TPyStringListIterator.CreateWith(PythonType: TPythonType; args,
243+
kwds: PPyObject);
244244
var
245245
_obj : PPyObject;
246246
_stringList : TPyStringList;

Demos/Demo32/Unit1.dfm

+12-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
1716
Visible = True
18-
PixelsPerInch = 96
1917
TextHeight = 13
2018
object Splitter1: TSplitter
2119
Left = 0
@@ -24,7 +22,6 @@ object Form1: TForm1
2422
Height = 3
2523
Cursor = crVSplit
2624
Align = alTop
27-
ExplicitWidth = 584
2825
end
2926
object Memo1: TMemo
3027
Left = 0
@@ -106,7 +103,18 @@ object Form1: TForm1
106103
'if p == spam.Point(2, 5):'
107104
' print ("Equal")'
108105
'else:'
109-
' print ("Not equal")')
106+
' print ("Not equal")'
107+
''
108+
109+
'print ("--------------------------------------------------------' +
110+
'----------")'
111+
'print("== create with keyword arguments ==")'
112+
'p = spam.Point(x=20, y=30)'
113+
'print(p)'
114+
'p = spam.Point(y = 30, x=20)'
115+
'print(p)'
116+
'p = spam.Point(20, y=30)'
117+
'print(p)')
110118
ParentFont = False
111119
ScrollBars = ssBoth
112120
TabOrder = 0

Demos/Demo32/Unit1.pas

+11-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ TPoint = class(TPersistent)
5959
TPyPoint = class(TPyDelphiPersistent)
6060
// Constructors & Destructors
6161
constructor Create( APythonType : TPythonType ); override;
62-
constructor CreateWith( PythonType : TPythonType; args : PPyObject ); override;
62+
constructor CreateWith(PythonType: TPythonType; args, kwds: PPyObject); override;
6363
// Basic services
6464
function Repr : PPyObject; override;
6565

@@ -106,12 +106,20 @@ constructor TPyPoint.Create( APythonType : TPythonType );
106106
// the Create constructor first, and because the constructors
107107
// are virtual, TPyPoint.Create will be automatically be called.
108108

109-
constructor TPyPoint.CreateWith( PythonType : TPythonType; args : PPyObject );
109+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
110+
var
111+
KeyArray: array of AnsiString;
112+
KeyPointerArray: array of PAnsiChar;
110113
begin
111114
inherited;
115+
KeyArray := ['x', 'y'];
116+
SetLength(KeyPointerArray, 3);
117+
KeyPointerArray[0] := PAnsiChar(KeyArray[0]);
118+
KeyPointerArray[1] := PAnsiChar(KeyArray[1]);
112119
with GetPythonEngine, DelphiObject as TPoint do
113120
begin
114-
if PyArg_ParseTuple( args, 'ii:CreatePoint',@fx, @fy ) = 0 then
121+
if PyArg_ParseTupleAndKeywords(args, kwds, 'ii:CreatePoint',
122+
@KeyPointerArray[0], @fx, @fy) = 0 then
115123
Exit;
116124
end;
117125
end;

Demos/Demo34/Unit1.dfm

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
1716
OnCreate = FormCreate
18-
PixelsPerInch = 96
1917
TextHeight = 13
2018
object Splitter1: TSplitter
2119
Left = 0
@@ -24,7 +22,6 @@ object Form1: TForm1
2422
Height = 3
2523
Cursor = crVSplit
2624
Align = alTop
27-
ExplicitWidth = 584
2825
end
2926
object Memo1: TMemo
3027
Left = 0

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 : PPyObject ); override;
46+
constructor CreateWith(PythonType: TPythonType; args, kwds: 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 : PPyObject );
161+
constructor TPyPoint.CreateWith(PythonType: TPythonType; args, kwds: PPyObject);
162162
begin
163163
inherited;
164164
with GetPythonEngine do

0 commit comments

Comments
 (0)