[fpc-pascal] Illegal type conversion: "LongInt" to "TObject"

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Jan 28 08:08:39 CET 2010


If I compile the code snippet shown below in 'mode delphi' it works fine.
If I try and compile it with 'mode objfpc' it fails with a compiler error
as shown here:

Error: Illegal type conversion: "LongInt" to "TObject"

// RTTI extension that allows "property paths".
//   eg:  tiSetProperty(MyObject, 'User.Address.City', 'Cape Town');
procedure tiSetProperty(const AObject: TObject; const APropPath: string;
  const APropValue: Variant);
  LPropInfo: PPropInfo;
  LValue: Variant;
  Assert(APropPath <> '', 'APropPath not assigned');
  LPropInfo := tiGetPropInfo(AObject.ClassType, APropPath, @AObject);
  if Assigned(LPropInfo) and Assigned(LPropInfo^.SetProc) then
    case tiGetTypeInfo(LPropInfo)^.Kind of
        SetObjectProp(AObject, LPropInfo, TObject(Integer(APropValue)));
  //                       ERROR OCCURS HERE  -------^


In both compiler modes, I am using the same FPC 2.4.0 compiler under a
64bit Linux system. What is the correct way to resolve this error in
compiler mode 'objfpc'?

Changing the offending line as shown below fixes the compiler error, but
I'm not 100% sure if that is what I'm supposed to do. I guessing here. :-(

  SetObjectProp(AObject, LPropInfo, TObject(PtrUInt(APropValue)));

  - Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

More information about the fpc-pascal mailing list