@@ -1031,6 +1031,9 @@ TExposedProperty = class(TExposedGetSet)
1031
1031
procedure RaiseNotifyEvent (PyDelphiWrapper : TPyDelphiWrapper; ACallable : PPyObject; Sender: TObject);
1032
1032
{ Sets mulptiple properties of PyObject from keywords argument}
1033
1033
function SetProperties (PyObject: PPyObject; keywords: PPyObject): PPyObject;
1034
+ function ValidateClassRef (PyValue: PPyObject; RefClass: TClass;
1035
+ out ClassRef: TClass; out ErrMsg: string): Boolean;
1036
+ procedure InvalidArguments (const MethName, ErrMsg : string);
1034
1037
1035
1038
implementation
1036
1039
@@ -1105,20 +1108,9 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
1105
1108
const AttrName: string; Value : PPyObject; PyDelphiWrapper: TPyDelphiWrapper;
1106
1109
out ErrMsg: string): Boolean; forward ;
1107
1110
1108
- function ValidateClassRef (PyValue: PPyObject; RefClass: TClass;
1109
- out ClassRef: TClass; out ErrMsg: string): Boolean; forward ;
1110
-
1111
1111
function ValidateClassProperty (PyValue: PPyObject; TypeInfo: PTypeInfo;
1112
1112
out Obj: TObject; out ErrMsg: string): Boolean; forward ;
1113
1113
1114
- procedure InvalidArguments (const MethName, ErrMsg : string);
1115
- begin
1116
- with GetPythonEngine do
1117
- PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString(
1118
- Format(rs_ErrInvalidArgs,
1119
- [MethName, ErrMsg])));
1120
- end ;
1121
-
1122
1114
{ TAbstractExposedMember }
1123
1115
1124
1116
constructor TAbstractExposedMember.Create(ARttiMember: TRttiMember;
@@ -1373,6 +1365,59 @@ function GlobalDelphiWrapper: TPyDelphiWrapper;
1373
1365
1374
1366
{ Helper functions }
1375
1367
1368
+ procedure InvalidArguments (const MethName, ErrMsg : string);
1369
+ begin
1370
+ with GetPythonEngine do
1371
+ PyErr_SetObject(PyExc_TypeError^, PyUnicodeFromString(
1372
+ Format(rs_ErrInvalidArgs,
1373
+ [MethName, ErrMsg])));
1374
+ end ;
1375
+
1376
+ function ValidateClassRef (PyValue: PPyObject; RefClass: TClass;
1377
+ out ClassRef: TClass; out ErrMsg: string): Boolean;
1378
+ var
1379
+ LTypeName: AnsiString;
1380
+ LPythonType: TPythonType;
1381
+ begin
1382
+ ClassRef := nil ;
1383
+ if (PyValue = GetPythonEngine.Py_None) then begin
1384
+ Result := True;
1385
+ Exit;
1386
+ end ;
1387
+
1388
+ Result := False;
1389
+ // Is PyValue a Python type?
1390
+ if PyValue^.ob_type^.tp_name = ' type' then
1391
+ LTypeName := PPyTypeObject(PyValue).tp_name
1392
+ else
1393
+ begin
1394
+ ErrMsg := rs_ExpectedClass;
1395
+ Exit;
1396
+ end ;
1397
+
1398
+ LPythonType := GetPythonEngine.FindPythonType(PPyTypeObject(PyValue));
1399
+ if not Assigned(LPythonType) then
1400
+ // Try once more with the base type to catter for pascal classes
1401
+ // subclassed in Python
1402
+ LPythonType := GetPythonEngine.FindPythonType(PPyTypeObject(PyValue).tp_base);
1403
+
1404
+ if Assigned(LPythonType) then
1405
+ begin
1406
+ if Assigned(LPythonType) and LPythonType.PyObjectClass.InheritsFrom(TPyDelphiObject) then
1407
+ begin
1408
+ ClassRef := TPyDelphiObjectClass(LPythonType.PyObjectClass).DelphiObjectClass;
1409
+ if ClassRef.InheritsFrom(RefClass) then
1410
+ Result := True
1411
+ else
1412
+ ErrMsg := rs_IncompatibleClasses;
1413
+ end
1414
+ else
1415
+ ErrMsg := rs_ExpectedClass;
1416
+ end
1417
+ else
1418
+ ErrMsg := rs_ExpectedClass;
1419
+ end ;
1420
+
1376
1421
{ $IFDEF EXTENDED_RTTI}
1377
1422
function DynArrayToPython (const Value : TValue): PPyObject;
1378
1423
var
@@ -1559,51 +1604,6 @@ function ValidateInterfaceProperty(PyValue: PPyObject; RttiType: TRttiInterfaceT
1559
1604
ErrMsg := rs_ExpectedInterface;
1560
1605
end ;
1561
1606
1562
- function ValidateClassRef (PyValue: PPyObject; RefClass: TClass;
1563
- out ClassRef: TClass; out ErrMsg: string): Boolean;
1564
- var
1565
- LTypeName: AnsiString;
1566
- LPythonType: TPythonType;
1567
- begin
1568
- ClassRef := nil ;
1569
- if (PyValue = GetPythonEngine.Py_None) then begin
1570
- Result := True;
1571
- Exit;
1572
- end ;
1573
-
1574
- Result := False;
1575
- // Is PyValue a Python type?
1576
- if PyValue^.ob_type^.tp_name = ' type' then
1577
- LTypeName := PPyTypeObject(PyValue).tp_name
1578
- else
1579
- begin
1580
- ErrMsg := rs_ExpectedClass;
1581
- Exit;
1582
- end ;
1583
-
1584
- LPythonType := GetPythonEngine.FindPythonType(PPyTypeObject(PyValue));
1585
- if not Assigned(LPythonType) then
1586
- // Try once more with the base type to catter for pascal classes
1587
- // subclassed in Python
1588
- LPythonType := GetPythonEngine.FindPythonType(PPyTypeObject(PyValue).tp_base);
1589
-
1590
- if Assigned(LPythonType) then
1591
- begin
1592
- if Assigned(LPythonType) and LPythonType.PyObjectClass.InheritsFrom(TPyDelphiObject) then
1593
- begin
1594
- ClassRef := TPyDelphiObjectClass(LPythonType.PyObjectClass).DelphiObjectClass;
1595
- if ClassRef.InheritsFrom(RefClass) then
1596
- Result := True
1597
- else
1598
- ErrMsg := rs_IncompatibleClasses;
1599
- end
1600
- else
1601
- ErrMsg := rs_ExpectedClass;
1602
- end
1603
- else
1604
- ErrMsg := rs_ExpectedClass;
1605
- end ;
1606
-
1607
1607
function ValidateDynArray (PyValue: PPyObject; const RttiParam: TRttiParameter; out ParamValue: TValue; out ErrMsg: string): Boolean;
1608
1608
var
1609
1609
Arr: array of TValue;
0 commit comments