@@ -1042,7 +1042,7 @@ implementation
1042
1042
rs_ExpectedNil = ' In static methods Self should be nil' ;
1043
1043
rs_ExpectedInterface = ' Expected a Pascal interface' ;
1044
1044
rs_ExpectedSequence = ' Expected a python sequence' ;
1045
- rsExpectedPPyObject = ' Expected a PPyObject ' ;
1045
+ rsExpectedPointer = ' Expected a Pointer ' ;
1046
1046
rs_InvalidClass = ' Invalid class' ;
1047
1047
rs_ErrEventNotReg = ' No Registered EventHandler for events of type "%s' ;
1048
1048
rs_ErrEventNoSuport = ' Class %s does not support events because it must ' +
@@ -2188,23 +2188,38 @@ function ValidateDynArray(PyValue: PPyObject; const RttiType: TRttiType;
2188
2188
end ;
2189
2189
end ;
2190
2190
2191
- function ValidatePPyObject (PyValue: PPyObject; const RttiType: TRttiType;
2191
+ function ValidatePointer (PyValue: PPyObject; const RttiType: TRttiType;
2192
2192
out ParamValue: TValue; out ErrMsg: string): Boolean;
2193
2193
var
2194
2194
RefType: TRttiType;
2195
+ PyEngine: TPythonEngine;
2196
+ P: Pointer;
2195
2197
begin
2196
2198
Result := False;
2199
+ PyEngine := GetPythonEngine;
2200
+
2197
2201
if (RTTIType is TRttiPointerType) then
2198
2202
begin
2199
2203
RefType := TRttiPointerType(RTTIType).ReferredType;
2200
2204
if Assigned(RefType) and (RefType.Name = ' PyObject' ) then
2201
2205
begin
2202
2206
Result := True;
2203
2207
ParamValue := TValue.From<PPyObject>(PyValue);
2208
+ end
2209
+ else if PyEngine.PyLong_Check(PyValue) then
2210
+ begin
2211
+ P := PyEngine.PyLong_AsVoidPtr(PyValue);
2212
+ if PyEngine.PyErr_Occurred = nil then
2213
+ begin
2214
+ Result := True;
2215
+ ParamValue := TValue.From<Pointer>(P);
2216
+ end
2217
+ else
2218
+ PyEngine.PyErr_Clear;
2204
2219
end ;
2205
2220
end ;
2206
2221
if not Result then
2207
- ErrMsg := rsExpectedPPyObject ;
2222
+ ErrMsg := rsExpectedPointer ;
2208
2223
end ;
2209
2224
2210
2225
function PyObjectToTValue (PyArg: PPyObject; ArgType: TRttiType;
@@ -2238,7 +2253,7 @@ function PyObjectToTValue(PyArg: PPyObject; ArgType: TRttiType;
2238
2253
tkDynArray:
2239
2254
Result := ValidateDynArray(PyArg, ArgType, Arg, ErrMsg);
2240
2255
tkPointer:
2241
- Result := ValidatePPyObject (PyArg, ArgType, Arg, ErrMsg);
2256
+ Result := ValidatePointer (PyArg, ArgType, Arg, ErrMsg);
2242
2257
else
2243
2258
Result := SimplePythonToValue(PyArg, ArgType.Handle, Arg, ErrMsg);
2244
2259
end ;
@@ -2277,7 +2292,7 @@ function TValueToPyObject(const Value: TValue;
2277
2292
DelphiWrapper: TPyDelphiWrapper; out ErrMsg: string): PPyObject;
2278
2293
begin
2279
2294
if Value .IsEmpty then
2280
- Result := GetPythonEngine .ReturnNone
2295
+ Result := DelphiWrapper.Engine .ReturnNone
2281
2296
else
2282
2297
case Value .Kind of
2283
2298
tkClass: Result := DelphiWrapper.Wrap(Value .AsObject);
@@ -2288,13 +2303,10 @@ function TValueToPyObject(const Value: TValue;
2288
2303
tkArray, tkDynArray:
2289
2304
Result := DynArrayToPython(Value , DelphiWrapper, ErrMsg);
2290
2305
tkPointer:
2291
- if Value .IsType< PPyObject> then
2306
+ if Value .TypeInfo = TypeInfo( PPyObject) then
2292
2307
Result := Value .AsType<PPyObject>
2293
2308
else
2294
- begin
2295
- Result := nil ;
2296
- ErrMsg := rs_ErrValueToPython;
2297
- end ;
2309
+ Result := DelphiWrapper.Engine.PyLong_FromVoidPtr(Value .AsType<Pointer>);
2298
2310
else
2299
2311
Result := SimpleValueToPython(Value , ErrMsg);
2300
2312
end ;
0 commit comments