[Lazarus] Python4Delphi/Lazarus: VarPyth: VarDataClear.. not yet supported?

Robert kxroberto at googlemail.com
Mon Jun 1 18:43:13 CEST 2009


Michael Van Canneyt wrote:
>
>
> On Sat, 30 May 2009, Robert wrote:
>>
>> i := pp.f();  // EVariantTypeCastError (i:Integer or LongInt)
>
> This needs investigation.
>

Found, that the origin of this casting problem is obviously, that 
TPythonVariantType.CastTo is not called by FPC, like it is in Delphi.
In variants.pp there are some ┬┤FindCustomVariantType ... 
Handler.CastTo┬┤s , but it does not work as it should?

When I switch VarPyth into Atom-Mode by the following {$IFDEF FPC}, this 
problem can be worked around for now. But some things are limited then....


### VarPyth.pas ###############
constructor TPythonData.Create(AObject: PPyObject);
begin
  PyObject := AObject;  // property; does XIncRef
  {$IFDEF FPC}
  //#TODO FreePascal Variants don't late-invoke our 
TPythonVariantType.CastTo/.Copy,
  // when the living Python object inside the Variant needs to be 
converted to a
  // static type.  ( v := pymod.a;  intvar := v; boolvar := v; ... )
  // As of 2009May31, v2.2.2 / v2.3.1.  So we have to use VarPyth in 
Atom-Mode,
  // and then a sterotype conversion to a Pascal type is tried as soon 
as the
  // variant receives the Python object (without knowing the target type 
/ best
  // conversion.
  // Remove this behavior as soon as we have full support for 
late-casting in FPC.
  fPythonAtomCompatible := True;
  {$ELSE}
  fPythonAtomCompatible := False;
  {$ENDIF}
end;



Robert





More information about the Lazarus mailing list