forked from lmbelo/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmMain.pas
More file actions
312 lines (291 loc) · 9.24 KB
/
fmMain.pas
File metadata and controls
312 lines (291 loc) · 9.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
unit fmMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ExtCtrls, StdCtrls, PythonEngine, PythonGUIInputOutput, Db,
DBTables, Grids, DBGrids;
type
TMain = class(TForm)
RichEdit1: TRichEdit;
PageControl1: TPageControl;
Splitter1: TSplitter;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
PythonEngine1: TPythonEngine;
PythonGUIInputOutput1: TPythonGUIInputOutput;
Memo1: TMemo;
Button1: TButton;
typeTable: TPythonType;
modDB: TPythonModule;
Table1: TTable;
Memo2: TMemo;
Panel1: TPanel;
DBGrid1: TDBGrid;
Button2: TButton;
DataSource1: TDataSource;
TabSheet3: TTabSheet;
Table1CustNo: TFloatField;
Table1Company: TStringField;
Table1Addr1: TStringField;
Table1Addr2: TStringField;
Table1City: TStringField;
Table1State: TStringField;
Table1Zip: TStringField;
Table1Country: TStringField;
Table1Phone: TStringField;
Table1FAX: TStringField;
Table1TaxRate: TFloatField;
Table1Contact: TStringField;
Table1LastInvoiceDate: TDateTimeField;
Table1Demo: TStringField;
Label1: TLabel;
typeQuery: TPythonType;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
Memo4: TMemo;
Splitter2: TSplitter;
Panel2: TPanel;
Button3: TButton;
Label2: TLabel;
Splitter3: TSplitter;
Memo3: TMemo;
Splitter4: TSplitter;
Panel3: TPanel;
Button4: TButton;
DBGrid2: TDBGrid;
DataSource2: TDataSource;
typeField: TPythonType;
TreeView1: TTreeView;
TabSheet6: TTabSheet;
Label3: TLabel;
Memo5: TMemo;
Panel4: TPanel;
Button5: TButton;
Splitter5: TSplitter;
typeVarArg: TPythonType;
TabSheet7: TTabSheet;
Label4: TLabel;
Memo6: TMemo;
Splitter6: TSplitter;
Panel5: TPanel;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure typeTableInitialization(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Table1CalcFields(DataSet: TDataSet);
procedure typeQueryInitialization(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure typeFieldInitialization(Sender: TObject);
procedure modDBAfterInitialization(Sender: TObject);
procedure modDBInitialization(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure typeVarArgInitialization(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Main: TMain;
implementation
uses pyDB, pyDBTables;
{$R *.DFM}
procedure TMain.Button1Click(Sender: TObject);
begin
with PythonEngine1 do
ExecStrings( Memo1.Lines );
end;
procedure TMain.typeTableInitialization(Sender: TObject);
begin
with Sender as TPythonType do
begin
PyObjectClass := TPyTable;
end;
end;
procedure TMain.Button2Click(Sender: TObject);
var
tbl : TPyTable;
obj : PPyObject;
begin
// Instantiate a new Python object TPyTable
obj := typeTable.CreateInstance;
tbl := PythonToDelphi(obj) as TPyTable;
// Attach our Delphi table to the Python object
tbl.SetDataset( Table1, False );
with GetPythonEngine do
begin
// Define a new variable "T" in the DB module
modDB.SetVar( 'T', obj );
Py_XDecRef(obj);
// Excecute the script
ExecStrings( memo2.Lines );
end;
end;
procedure TMain.Table1CalcFields(DataSet: TDataSet);
begin
Dataset.FieldByName('Demo').AsString := Dataset.FieldByName('State').AsString + ' - ' +
Dataset.FieldByName('Zip').AsString;
end;
procedure TMain.typeQueryInitialization(Sender: TObject);
begin
with Sender as TPythonType do
begin
PyObjectClass := TPyQuery;
end;
end;
procedure TMain.Button3Click(Sender: TObject);
begin
with PythonEngine1 do
ExecStrings( Memo4.Lines );
end;
procedure TMain.Button4Click(Sender: TObject);
var
tbl : TPyTable;
obj : PPyObject;
begin
// Instantiate a new Python object TPyTable
obj := typeTable.CreateInstance;
tbl := PythonToDelphi(obj) as TPyTable;
// connect the Datasource2 to the Python TTable
Datasource2.Dataset := tbl.Table;
with GetPythonEngine do
begin
// Define a new variable "T" in the DB module
modDB.SetVar( 'T', obj );
Py_XDecRef(obj);
// Excecute the script
ExecStrings( memo3.Lines );
end;
end;
procedure TMain.FormCreate(Sender: TObject);
begin
Memo1.Lines.LoadFromFile( 'Example1.py' );
Memo2.Lines.LoadFromFile( 'Example2.py' );
Memo3.Lines.LoadFromFile( 'Example3.py' );
Memo4.Lines.LoadFromFile( 'Example4.py' );
Memo5.Lines.LoadFromFile( 'Example5.py' );
Memo6.Lines.LoadFromFile( 'Example6.py' );
PageControl1.ActivePage := TabSheet1;
end;
procedure TMain.typeFieldInitialization(Sender: TObject);
begin
with Sender as TPythonType do
begin
PyObjectClass := TPyField;
end;
gFieldType := Sender as TPythonType;
end;
procedure TMain.modDBAfterInitialization(Sender: TObject);
begin
with Sender as TPythonModule do
begin
// Values for type TTableType
SetVarFromVariant( 'ttDefault', 0 );
SetVarFromVariant( 'ttParadox', 1 );
SetVarFromVariant( 'ttDBase', 2 );
SetVarFromVariant( 'ttASCII', 3 );
// Values for type TDatasetState
SetVarFromVariant( 'dsInactive', 0 );
SetVarFromVariant( 'dsBrowse', 1 );
SetVarFromVariant( 'dsEdit', 2 );
SetVarFromVariant( 'dsInsert', 3 );
SetVarFromVariant( 'dsSetKey', 4 );
SetVarFromVariant( 'dsCalcFields', 5 );
SetVarFromVariant( 'dsFilter', 6 );
SetVarFromVariant( 'dsNewValue', 7 );
SetVarFromVariant( 'dsOldValue', 8 );
SetVarFromVariant( 'dsCurValue', 9 );
// Values for type TFieldType
SetVarFromVariant( 'ftUnknown', 0 );
SetVarFromVariant( 'ftString', 1 );
SetVarFromVariant( 'ftSmallint', 2 );
SetVarFromVariant( 'ftInteger', 3 );
SetVarFromVariant( 'ftWord', 4 );
SetVarFromVariant( 'ftBoolean', 5 );
SetVarFromVariant( 'ftFloat', 6 );
SetVarFromVariant( 'ftCurrency', 7 );
SetVarFromVariant( 'ftBCD', 8 );
SetVarFromVariant( 'ftDate', 9 );
SetVarFromVariant( 'ftTime', 10 );
SetVarFromVariant( 'ftDateTime', 11 );
SetVarFromVariant( 'ftBytes', 12 );
SetVarFromVariant( 'ftVarBytes', 13 );
SetVarFromVariant( 'ftAutoInc', 14 );
SetVarFromVariant( 'ftBlob', 15 );
SetVarFromVariant( 'ftMemo', 16 );
SetVarFromVariant( 'ftGraphic', 17 );
SetVarFromVariant( 'ftFmtMemo', 18 );
SetVarFromVariant( 'ftParadoxOle', 19 );
SetVarFromVariant( 'ftDBaseOle', 20 );
SetVarFromVariant( 'ftTypedBinary', 21 );
SetVarFromVariant( 'ftCursor', 22 );
// Values for type TFieldKind
SetVarFromVariant( 'fkData', 0 );
SetVarFromVariant( 'fkCalculated', 1 );
SetVarFromVariant( 'fkLookup', 2 );
SetVarFromVariant( 'fkInternalCalc', 3 );
// Values for type TLocateOption
SetVarFromVariant( 'loCaseInsensitive', 0 );
SetVarFromVariant( 'loPartialKey', 1 );
// Values for type TLockType
SetVarFromVariant( 'ltReadLock', 0 );
SetVarFromVariant( 'ltWriteLock', 1 );
// Values for type TIndexOptions
SetVarFromVariant( 'ixPrimary', 0 );
SetVarFromVariant( 'ixUnique', 1 );
SetVarFromVariant( 'ixDescending', 2 );
SetVarFromVariant( 'ixCaseInsensitive', 3 );
SetVarFromVariant( 'ixExpression', 4 );
// Values for type TDataAction
SetVarFromVariant( 'daFail', 0 );
SetVarFromVariant( 'daAbort', 1 );
SetVarFromVariant( 'daRetry', 2 );
// Values for type TUpdateKind
SetVarFromVariant( 'ukModify', 0 );
SetVarFromVariant( 'ukInsert', 1 );
SetVarFromVariant( 'ukDelete', 2 );
// Values for type TUpdateAction
SetVarFromVariant( 'uaFail', 0 );
SetVarFromVariant( 'uaAbort', 1 );
SetVarFromVariant( 'uaSkip', 2 );
SetVarFromVariant( 'uaRetry', 3 );
SetVarFromVariant( 'uaApplied', 4 );
end;
end;
procedure TMain.modDBInitialization(Sender: TObject);
begin
with Sender as TPythonModule do
begin
with DocString do
begin
Add( 'This module contains several Object Types that' );
Add( 'will let you work with the Borland BDE and access' );
Add( 'a database.' );
Add( '' );
Add( 'CreateTTable() -> creates a TTable instance' );
Add( 'CreateTQuery() -> creates a TQuery instance' );
end;
end;
end;
procedure TMain.Button5Click(Sender: TObject);
begin
with PythonEngine1 do
ExecStrings( Memo5.Lines );
end;
procedure TMain.typeVarArgInitialization(Sender: TObject);
begin
with Sender as TPythonType do
begin
PyObjectClass := TVarArg;
end;
gVarArgType := Sender as TPythonType;
end;
procedure TMain.Button6Click(Sender: TObject);
begin
with PythonEngine1 do
ExecStrings( Memo6.Lines );
end;
end.