@@ -1038,6 +1038,7 @@ implementation
10381038 rs_ExpectedNil = ' In static methods Self should be nil' ;
10391039 rs_ExpectedInterface = ' Expected a Pascal interface' ;
10401040 rs_ExpectedSequence = ' Expected a python sequence' ;
1041+ rsExpectedPPyObject = ' Expected a PPyObject' ;
10411042 rs_InvalidClass = ' Invalid class' ;
10421043 rs_ErrEventNotReg = ' No Registered EventHandler for events of type "%s' ;
10431044 rs_ErrEventNoSuport = ' Class %s does not support events because it must ' +
@@ -2176,6 +2177,25 @@ function ValidateDynArray(PyValue: PPyObject; const RttiType: TRttiType;
21762177 end ;
21772178end ;
21782179
2180+ function ValidatePPyObject (PyValue: PPyObject; const RttiType: TRttiType;
2181+ out ParamValue: TValue; out ErrMsg: string): Boolean;
2182+ var
2183+ RefType: TRttiType;
2184+ begin
2185+ Result := False;
2186+ if (RTTIType is TRttiPointerType) then
2187+ begin
2188+ RefType := TRttiPointerType(RTTIType).ReferredType;
2189+ if Assigned(RefType) and (RefType.Name = ' PyObject' ) then
2190+ begin
2191+ Result := True;
2192+ ParamValue := TValue.From<PPyObject>(PyValue);
2193+ end ;
2194+ end ;
2195+ if not Result then
2196+ ErrMsg := rsExpectedPPyObject;
2197+ end ;
2198+
21792199function PyObjectToTValue (PyArg: PPyObject; ArgType: TRttiType;
21802200 out Arg: TValue; out ErrMsg: string): Boolean;
21812201var
@@ -2205,7 +2225,9 @@ function PyObjectToTValue(PyArg: PPyObject; ArgType: TRttiType;
22052225 tkRecord{ $IFDEF MANAGED_RECORD} , tkMRecord{ $ENDIF} :
22062226 Result := ValidateRecordProperty(PyArg, ArgType.Handle, Arg, ErrMsg);
22072227 tkDynArray:
2208- Result := ValidateDynArray(PyArg, ArgType, Arg, ErrMsg)
2228+ Result := ValidateDynArray(PyArg, ArgType, Arg, ErrMsg);
2229+ tkPointer:
2230+ Result := ValidatePPyObject(PyArg, ArgType, Arg, ErrMsg);
22092231 else
22102232 Result := SimplePythonToValue(PyArg, ArgType.Handle, Arg, ErrMsg);
22112233 end ;
@@ -2254,6 +2276,14 @@ function TValueToPyObject(const Value: TValue;
22542276 Result := DelphiWrapper.WrapRecord(Value );
22552277 tkArray, tkDynArray:
22562278 Result := DynArrayToPython(Value , DelphiWrapper, ErrMsg);
2279+ tkPointer:
2280+ if Value .IsType<PPyObject> then
2281+ Result := Value .AsType<PPyObject>
2282+ else
2283+ begin
2284+ Result := nil ;
2285+ ErrMsg := rs_ErrValueToPython;
2286+ end ;
22572287 else
22582288 Result := SimpleValueToPython(Value , ErrMsg);
22592289 end ;
@@ -4127,7 +4157,7 @@ class procedure TPyDelphiObject.ExposeMethods(AClass: TClass;
41274157
41284158 // Ignore methods with unhandled return type
41294159 if Assigned(LRttiMethod.ReturnType) and (LRttiMethod.ReturnType.TypeKind
4130- in [tkUnknown, tkMethod, tkPointer, tkProcedure])
4160+ in [tkUnknown, tkMethod, tkProcedure])
41314161 then
41324162 Continue;
41334163
@@ -4229,7 +4259,7 @@ class procedure TPyDelphiObject.ExposeFields(AClass: TClass;
42294259 Continue;
42304260
42314261 // Skip if the type cannot be handled
4232- if LRttiField.FieldType.TypeKind in [tkUnknown, tkMethod, tkPointer, tkProcedure] then
4262+ if LRttiField.FieldType.TypeKind in [tkUnknown, tkMethod, tkProcedure] then
42334263 Continue;
42344264
42354265 AddedFields := AddedFields + [LRttiField.Name ];
@@ -4315,7 +4345,7 @@ class procedure TPyDelphiObject.ExposeProperties(AClass: TClass;
43154345 else
43164346 begin
43174347 // Skip if the type cannot be handled
4318- if LRttiProperty.PropertyType.TypeKind in [tkUnknown, tkPointer, tkMethod, tkProcedure] then
4348+ if LRttiProperty.PropertyType.TypeKind in [tkUnknown, tkMethod, tkProcedure] then
43194349 Continue;
43204350
43214351 // Create the exposed property
@@ -4399,7 +4429,7 @@ class procedure TPyDelphiObject.ExposeIndexedProperties(AClass: TClass;
43994429 Continue;
44004430
44014431 // Skip if the type cannot be handled
4402- if LRttiProperty.PropertyType.TypeKind in [tkUnknown, tkPointer, tkMethod, tkProcedure] then
4432+ if LRttiProperty.PropertyType.TypeKind in [tkUnknown, tkMethod, tkProcedure] then
44034433 Continue;
44044434
44054435 AddedProperties := AddedProperties + [LRttiProperty.Name ];
0 commit comments