@@ -25,13 +25,11 @@ TForm1 = class(TForm)
25
25
procedure FormCreate (Sender: TObject);
26
26
procedure cbPyVersionsSelect (Sender: TObject);
27
27
private
28
- { Déclarations privées }
29
28
PythonEngine1: TPythonEngine;
30
29
PythonModule1: TPythonModule;
31
30
PythonType1: TPythonType;
32
31
PyVersions: TPythonVersions;
33
32
public
34
- { Déclarations publiques }
35
33
procedure CreatePythonComponents ;
36
34
end ;
37
35
@@ -40,8 +38,8 @@ TForm1 = class(TForm)
40
38
// Then it must override some methods, like the constructors,
41
39
// the RegisterMethods and the type services' virtual methods.
42
40
TPyPoint = class (TPyObject)
43
- x, y : Integer;
44
- Name : String;
41
+ x, y: Integer;
42
+ Name : String;
45
43
46
44
// Constructors & Destructors
47
45
constructor Create( APythonType : TPythonType ); override;
@@ -96,7 +94,6 @@ procedure TForm1.CreatePythonComponents;
96
94
97
95
PythonEngine1.IO := PythonGUIInputOutput1;
98
96
99
-
100
97
{ TPythonModule }
101
98
PythonModule1 := TPythonModule.Create(Self);
102
99
@@ -131,8 +128,8 @@ procedure TForm1.CreatePythonComponents;
131
128
end ;
132
129
133
130
procedure TForm1.FormCreate (Sender: TObject);
134
- Var
135
- PyVersion : TPythonVersion;
131
+ var
132
+ PyVersion: TPythonVersion;
136
133
begin
137
134
PyVersions := GetRegisteredPythonVersions;
138
135
for PyVersion in PyVersions do
@@ -143,7 +140,6 @@ procedure TForm1.FormCreate(Sender: TObject);
143
140
end ;
144
141
end ;
145
142
146
-
147
143
// First, we need to initialize the property PyObjectClass with
148
144
// the class of our Type object
149
145
procedure TForm1.PythonType1Initialization (Sender: TObject);
@@ -163,7 +159,7 @@ constructor TPyPoint.Create( APythonType : TPythonType );
163
159
// Don't call the Create constructor of TPyPoint, because
164
160
// we call the inherited constructor CreateWith that calls
165
161
// the Create constructor first, and because the constructors
166
- // are virtual, TPyPoint.Create will be automatically be called.
162
+ // are virtual, TPyPoint.Create will automatically be called.
167
163
168
164
constructor TPyPoint.CreateWith( PythonType : TPythonType; args : PPyObject );
169
165
begin
@@ -257,16 +253,16 @@ procedure TPyPoint.OffsetBy( dx, dy : Integer );
257
253
258
254
function TPyPoint.DoOffsetBy ( args : PPyObject ) : PPyObject;
259
255
var
260
- dx, dy : Integer;
256
+ dx, dy: Integer;
261
257
begin
262
258
with GetPythonEngine do
263
259
begin
264
260
// We adjust the transmitted self argument
265
261
Adjust(@Self);
266
262
// first we extract the arguments
267
- if PyArg_ParseTuple( args, ' ii:Point.Offset' ,@dx, @dy ) <> 0 then
263
+ if PyArg_ParseTuple( args, ' ii:Point.Offset' , @dx, @dy ) <> 0 then
268
264
begin
269
- // if it's ok, then we call the method that does the job
265
+ // if it's ok, we call the method that does the job
270
266
// with the correct arguments
271
267
OffsetBy( dx, dy );
272
268
// Finally, we return nothing
@@ -299,16 +295,15 @@ function TPyPoint.DoRaiseError( args : PPyObject ) : PPyObject;
299
295
300
296
// ///////////////////////////////////////////////
301
297
302
-
303
298
procedure TForm1.Button1Click (Sender: TObject);
304
299
var
305
- DelphiPoint : TPyPoint;
306
- p : PPyObject;
300
+ DelphiPoint: TPyPoint;
301
+ p: PPyObject;
307
302
begin
308
303
// Here's how you can create/read Python vars from Delphi with
309
304
// Delphi/Python objects.
310
305
311
- // You should ask to the TPythonType to create an instance of its type
306
+ // You should ask the TPythonType to create an instance of its type
312
307
// because it will do some initialization. You can use CreateInstanceWith
313
308
// if you want to transmit some Python arguments.
314
309
// We receive a Python object pointer
@@ -317,10 +312,10 @@ procedure TForm1.Button1Click(Sender: TObject);
317
312
// Then we cast the python object to the right delphi type
318
313
DelphiPoint := TPyPoint( PythonToDelphi(p) );
319
314
// We do some changes on the delphi object
320
- DelphiPoint.X:= 10 ;
321
- DelphiPoint.Y:= 20 ;
315
+ DelphiPoint.X := 10 ;
316
+ DelphiPoint.Y := 20 ;
322
317
// Add variable "myPoint" in the module "spam".
323
- // So you'll access to the var in the module called spam with:
318
+ // So you'll have access to the var in the module called spam with:
324
319
// import spam
325
320
// print spam.myPoint
326
321
PythonModule1.SetVar( ' myPoint' , p );
0 commit comments