Skip to content

Commit 45ca26c

Browse files
committed
Call to inherited removed from RegisterMethods and RegisterGetSets, following the fix to #382
1 parent a945a65 commit 45ca26c

17 files changed

+1577
-1658
lines changed

Source/PythonEngine.pas

+11-5
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ TPythonInterface=class(TDynamicDll)
14921492
PyMapping_HasKeyString:function (ob:PPyObject;key:PAnsiChar):integer; cdecl;
14931493
PyMapping_Length:function (ob:PPyObject):NativeInt; cdecl;
14941494
PyMapping_SetItemString:function (ob:PPyObject; key:PAnsiChar; value:PPyObject):integer; cdecl;
1495+
PyMapping_Keys:function(mp: PPyObject):PPyObject; cdecl;
1496+
PyMapping_Values:function(mp: PPyObject):PPyObject; cdecl;
14951497
PyMethod_Function:function (ob:PPyObject):PPyObject; cdecl;
14961498
PyMethod_New:function (ob1,ob2,ob3:PPyObject):PPyObject; cdecl;
14971499
PyMethod_Self:function (ob:PPyObject):PPyObject; cdecl;
@@ -1917,7 +1919,7 @@ TPythonEngine = class(TPythonInterface)
19171919
function ArrayToPyDict( const items : array of const) : PPyObject;
19181920
function StringsToPyList( strings : TStrings ) : PPyObject;
19191921
function StringsToPyTuple( strings : TStrings ) : PPyObject;
1920-
procedure PyListToStrings( list : PPyObject; strings : TStrings );
1922+
procedure PyListToStrings(list: PPyObject; Strings: TStrings; ClearStrings: Boolean = True);
19211923
procedure PyTupleToStrings( tuple: PPyObject; strings : TStrings );
19221924
function ReturnNone : PPyObject;
19231925
function ReturnTrue : PPyObject;
@@ -3687,6 +3689,8 @@ procedure TPythonInterface.MapDll;
36873689
PyMapping_HasKeyString := Import('PyMapping_HasKeyString');
36883690
PyMapping_Length := Import('PyMapping_Length');
36893691
PyMapping_SetItemString := Import('PyMapping_SetItemString');
3692+
PyMapping_Keys := Import('PyMapping_Keys');
3693+
PyMapping_Values := Import('PyMapping_Values');
36903694
PyMethod_Function := Import('PyMethod_Function');
36913695
PyMethod_New := Import('PyMethod_New');
36923696
PyMethod_Self := Import('PyMethod_Self');
@@ -6013,15 +6017,17 @@ function TPythonEngine.StringsToPyTuple( strings : TStrings ) : PPyObject;
60136017
PyUnicodeFromString(strings.Strings[i]));
60146018
end;
60156019

6016-
procedure TPythonEngine.PyListToStrings( list : PPyObject; strings : TStrings );
6020+
procedure TPythonEngine.PyListToStrings(list: PPyObject; Strings: TStrings;
6021+
ClearStrings: Boolean = True);
60176022
var
60186023
i : Integer;
60196024
begin
60206025
if not PyList_Check(list) then
60216026
raise EPythonError.Create('the python object is not a list');
6022-
strings.Clear;
6027+
if ClearStrings then
6028+
Strings.Clear;
60236029
for i := 0 to PyList_Size( list ) - 1 do
6024-
strings.Add( PyObjectAsString( PyList_GetItem( list, i ) ) );
6030+
Strings.Add( PyObjectAsString( PyList_GetItem( list, i ) ) );
60256031
end;
60266032

60276033
procedure TPythonEngine.PyTupleToStrings( tuple: PPyObject; strings : TStrings );
@@ -6279,7 +6285,7 @@ function TPythonEngine.GetMainModule : PPyObject;
62796285
Result := PyImport_AddModule(PAnsiChar(ExecModule));
62806286
end;
62816287

6282-
function TPythonEngine.PyTimeStruct_Check( obj : PPyObject ) : Boolean;
6288+
function TPythonEngine.PyTimeStruct_Check(obj : PPyObject): Boolean;
62836289
begin
62846290
Result := Assigned(FTimeStruct) and (Pointer(obj^.ob_type) = FTimeStruct);
62856291
end;

Source/WrapDelphi.pas

+29-6
Original file line numberDiff line numberDiff line change
@@ -2352,8 +2352,27 @@ function TPyDelphiObject.Get_Owned(Acontext: Pointer): PPyObject;
23522352

23532353
function TPyDelphiObject.Dir_Wrapper(args: PPyObject): PPyObject;
23542354
var
2355-
i : Integer;
23562355
SL : TStringList;
2356+
PyEngine: TPythonEngine;
2357+
2358+
procedure AddItemsFromDict(PyObj: PPyObject);
2359+
var
2360+
PyDict: PPyObject;
2361+
PyList: PPyObject;
2362+
begin
2363+
if PyEngine.PyObject_HasAttrString(PyObj, '__dict__') = 1 then
2364+
begin
2365+
PyDict := PyEngine.PyObject_GetAttrString(PyObj, '__dict__');
2366+
PyList := PyEngine.PyMapping_Keys(PyDict);
2367+
if Assigned(PyList) then
2368+
PyEngine.PyListToStrings(PyList, SL, False);
2369+
PyEngine.Py_XDECREF(PyList);
2370+
PyEngine.Py_XDECREF(PyDict);
2371+
end;
2372+
end;
2373+
2374+
var
2375+
PyType: PPyTypeObject;
23572376
{$IFDEF EXTENDED_RTTI}
23582377
Context: TRttiContext;
23592378
RttiType: TRTTIType;
@@ -2366,12 +2385,16 @@ function TPyDelphiObject.Dir_Wrapper(args: PPyObject): PPyObject;
23662385
SL := TStringList.Create;
23672386
SL.Sorted := True;
23682387
SL.Duplicates := dupIgnore;
2388+
PyEngine := GetPythonEngine;
23692389
try
2370-
// Add methods
2371-
for i := 0 to PythonType.MethodCount - 1 do
2372-
SL.Add(string(AnsiString(PythonType.Methods[i].ml_name)));
2373-
for i := 0 to PythonType.GetSetCount - 1 do
2374-
SL.Add(string(AnsiString(PythonType.GetSet[i].name)));
2390+
AddItemsFromDict(GetSelf);
2391+
PyType := PythonType.TheTypePtr;
2392+
while PyType <> nil do
2393+
begin
2394+
AddItemsFromDict(PPyObject(PyType));
2395+
PyType := PyType.tp_base;
2396+
end;
2397+
23752398
{$IFDEF EXTENDED_RTTI}
23762399
Context := TRttiContext.Create();
23772400
try

Source/WrapDelphiClasses.pas

-9
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ function TPyDelphiPersistent.GetNamePath_Wrapper(
391391
class procedure TPyDelphiPersistent.RegisterMethods(
392392
PythonType: TPythonType);
393393
begin
394-
inherited;
395394
PythonType.AddMethod('Assign', @TPyDelphiPersistent.Assign_Wrapper,
396395
'TPersistent.Assign(persistent)'#10 +
397396
'Assigns to this object the values of another TPersistent object');
@@ -584,7 +583,6 @@ function TPyDelphiCollection.Insert_Wrapper(args: PPyObject): PPyObject;
584583

585584
class procedure TPyDelphiCollection.RegisterGetSets(PythonType: TPythonType);
586585
begin
587-
inherited;
588586
with PythonType do
589587
begin
590588
AddGetSet('Count', @TPyDelphiCollection.Get_Count, nil,
@@ -599,7 +597,6 @@ class procedure TPyDelphiCollection.RegisterGetSets(PythonType: TPythonType);
599597
class procedure TPyDelphiCollection.RegisterMethods(
600598
PythonType: TPythonType);
601599
begin
602-
inherited;
603600
PythonType.AddMethod('Insert', @TPyDelphiCollection.Insert_Wrapper,
604601
'TCollection.Insert(Index)'#10 +
605602
'Inserts a new collection item to the collection at the Index position');
@@ -998,7 +995,6 @@ procedure TPyDelphiComponent.SetDelphiObject(const Value: TComponent);
998995
class procedure TPyDelphiComponent.RegisterGetSets(
999996
PythonType: TPythonType);
1000997
begin
1001-
inherited;
1002998
with PythonType do
1003999
begin
10041000
AddGetSet('ComponentCount', @TPyDelphiComponent.Get_ComponentCount, nil,
@@ -1013,7 +1009,6 @@ class procedure TPyDelphiComponent.RegisterGetSets(
10131009
class procedure TPyDelphiComponent.RegisterMethods(
10141010
PythonType: TPythonType);
10151011
begin
1016-
inherited;
10171012
PythonType.AddMethod('GetParentComponent', @TPyDelphiComponent.GetParentComponent_Wrapper,
10181013
'TComponent.GetParentComponent()'#10 +
10191014
'Returns the parent of a component.');
@@ -1462,7 +1457,6 @@ function TPyDelphiStrings.MpSubscript(obj: PPyObject): PPyObject;
14621457

14631458
class procedure TPyDelphiStrings.RegisterGetSets(PythonType: TPythonType);
14641459
begin
1465-
inherited;
14661460
with PythonType do
14671461
begin
14681462
AddGetSet('Capacity', @TPyDelphiStrings.Get_Capacity, @TPyDelphiStrings.Set_Capacity,
@@ -1476,7 +1470,6 @@ class procedure TPyDelphiStrings.RegisterGetSets(PythonType: TPythonType);
14761470

14771471
class procedure TPyDelphiStrings.RegisterMethods(PythonType: TPythonType);
14781472
begin
1479-
inherited;
14801473
PythonType.AddMethod('Add', @TPyDelphiStrings.Add_Wrapper,
14811474
'TStrings.Add(s)'#10 +
14821475
'Adds a string to the TStrings object and returns the index position');
@@ -1573,7 +1566,6 @@ function TPyDelphiBasicAction.Get_ActionComponent(AContext: Pointer): PPyObject;
15731566
class procedure TPyDelphiBasicAction.RegisterGetSets(
15741567
PythonType: TPythonType);
15751568
begin
1576-
inherited;
15771569
with PythonType do
15781570
begin
15791571
AddGetSet('ActionComponent', @TPyDelphiBasicAction.Get_ActionComponent, @TPyDelphiBasicAction.Set_ActionComponent,
@@ -1584,7 +1576,6 @@ class procedure TPyDelphiBasicAction.RegisterGetSets(
15841576
class procedure TPyDelphiBasicAction.RegisterMethods(
15851577
PythonType: TPythonType);
15861578
begin
1587-
inherited;
15881579
PythonType.AddMethod('Execute', @TPyDelphiBasicAction.Execute_Wrapper,
15891580
'TBasicAction.Execute()'#10 +
15901581
'Generates an OnExecute event.');

Source/WrapFireDAC.pas

-5
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ procedure TPyDBField.SetDelphiObject(const Value: TField);
570570

571571
class procedure TPyDBField.RegisterMethods( PythonType : TPythonType );
572572
begin
573-
inherited;
574573
with PythonType do begin
575574
AddMethod(AnsiString('Clear'), @TPyDBField.Do_Clear,
576575
AnsiString('DBField.Clear() -> None') );
@@ -836,7 +835,6 @@ function TPyDBDataset.Get_Rows(AContext: Pointer): PPyObject;
836835

837836
class procedure TPyDBDataset.RegisterGetSets( PythonType : TPythonType );
838837
begin
839-
inherited;
840838
PythonType.AddGetSet(PAnsiChar('RowsCount'), @TPyDBDataset.Get_RowsCount, nil,
841839
PAnsiChar('Returns the count of contained dataset rows'), nil);
842840
PythonType.AddGetSet(PAnsiChar('Rows'), @TPyDBDataset.Get_Rows, nil,
@@ -845,7 +843,6 @@ class procedure TPyDBDataset.RegisterGetSets( PythonType : TPythonType );
845843

846844
class procedure TPyDBDataset.RegisterMethods( PythonType : TPythonType );
847845
begin
848-
inherited;
849846
with PythonType do begin
850847
AddMethod(AnsiString('Fields'), @TPyDBDataset.Do_Fields,
851848
AnsiString('DBDataset.Fields( index : Integer ) -> TField') );
@@ -1341,7 +1338,6 @@ destructor TPyDBTable.Destroy;
13411338

13421339
class procedure TPyDBTable.RegisterMethods( PythonType : TPythonType );
13431340
begin
1344-
inherited;
13451341
with PythonType do begin
13461342
AddMethod(AnsiString('Open'), @TPyDBTable.Do_Open,
13471343
AnsiString('FDTable.Open() -> None') );
@@ -1925,7 +1921,6 @@ destructor TPyDBQuery.Destroy;
19251921

19261922
class procedure TPyDBQuery.RegisterMethods( PythonType : TPythonType );
19271923
begin
1928-
inherited;
19291924
with PythonType do begin
19301925
AddMethod(AnsiString('Open'), @TPyDBQuery.Do_Open,
19311926
AnsiString('FDQuery.Open() -> None') );

Source/fmx/WrapFmxControls.pas

-4
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ function TPyDelphiControl.Get_Visible(AContext: Pointer): PPyObject;
302302

303303
class procedure TPyDelphiControl.RegisterGetSets(PythonType: TPythonType);
304304
begin
305-
inherited;
306305
PythonType.AddGetSet('Visible', @TPyDelphiControl.Get_Visible, @TPyDelphiControl.Set_Visible,
307306
'Returns/Sets the Control Visibility', nil);
308307
PythonType.AddGetSet('ControlsCount', @TPyDelphiControl.Get_ControlsCount, nil,
@@ -317,7 +316,6 @@ class procedure TPyDelphiControl.RegisterGetSets(PythonType: TPythonType);
317316

318317
class procedure TPyDelphiControl.RegisterMethods(PythonType: TPythonType);
319318
begin
320-
inherited;
321319
PythonType.AddMethod('BringToFront', @TPyDelphiControl.BringToFront_Wrapper,
322320
'TControl.BringToFront()'#10 +
323321
'Puts the control in front of all other controls in its parent control.');
@@ -628,7 +626,6 @@ function TPyDelphiStyledControl.NeedStyleLookup_Wrapper(
628626

629627
class procedure TPyDelphiStyledControl.RegisterGetSets(PythonType: TPythonType);
630628
begin
631-
inherited;
632629
with PythonType do begin
633630
AddGetSet('DefaultStyleLookupName', @TPyDelphiStyledControl.Get_StyleLookup, nil,
634631
'Returns a string with the name of the default style of this control', nil);
@@ -648,7 +645,6 @@ class procedure TPyDelphiStyledControl.RegisterGetSets(PythonType: TPythonType);
648645

649646
class procedure TPyDelphiStyledControl.RegisterMethods(PythonType: TPythonType);
650647
begin
651-
inherited;
652648
PythonType.AddMethod('ApplyStyleLookup', @TPyDelphiStyledControl.ApplyStyleLookup_Wrapper,
653649
'TStyledControl.ApplyStyleLookup()'#10 +
654650
'Gets and applies the style of a TStyledControl.');

Source/fmx/WrapFmxDialogs.pas

-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,12 @@ function TPyDelphiOpenDialog.Get_filename(AContext: Pointer): PPyObject;
9292

9393
class procedure TPyDelphiOpenDialog.RegisterGetSets(PythonType: TPythonType);
9494
begin
95-
inherited;
9695
PythonType.AddGetSet('FileName', @TPyDelphiOpenDialog.Get_filename,
9796
nil, '', nil);
9897
end;
9998

10099
class procedure TPyDelphiOpenDialog.RegisterMethods(PythonType: TPythonType);
101100
begin
102-
inherited;
103101
PythonType.AddMethod('Execute', @TPyDelphiOpenDialog.Execute_Wrapper,
104102
'TOpenDialog.Execute()'#10 +
105103
'Displays the dialog');

Source/fmx/WrapFmxForms.pas

-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ function TPyDelphiApplication.Run_Wrapper(AArgs: PPyObject): PPyObject;
248248

249249
class procedure TPyDelphiApplication.RegisterMethods(APythonType: TPythonType);
250250
begin
251-
inherited;
252251
with APythonType do begin
253252
AddMethod('Initialize', @TPyDelphiApplication.Initialize_Wrapper,
254253
'TApplication.Initialize()'#10 +
@@ -449,7 +448,6 @@ function TPyDelphiCommonCustomForm.LoadProps_Wrapper(
449448
class procedure TPyDelphiCommonCustomForm.RegisterMethods(
450449
PythonType: TPythonType);
451450
begin
452-
inherited;
453451
PythonType.AddMethod('LoadProps', @TPyDelphiCustomForm.LoadProps_Wrapper,
454452
'TCommonCustomForm.LoadProps()'#10 +
455453
'Load properties from a .pydfm file');

Source/fmx/WrapFmxMedia.pas

-2
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,11 @@ class function TPyDelphiCameraComponent.DelphiObjectClass: TClass;
247247
class procedure TPyDelphiCameraComponent.RegisterGetSets
248248
(PythonType: TPythonType);
249249
begin
250-
inherited;
251250
end;
252251

253252
class procedure TPyDelphiCameraComponent.RegisterMethods
254253
(PythonType: TPythonType);
255254
begin
256-
inherited;
257255
end;
258256

259257
function TPyDelphiCameraComponent.GetDelphiObject: TCameraComponent;

0 commit comments

Comments
 (0)