Michael Van Canneyt
Thu, 28 Jan 2010 00:31:07 -0800
On Thu, 28 Jan 2010, Graeme Geldenhuys wrote:
Hi,
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:
/home/graemeg/programming/personal/fpginstall/src/rttihelpers.pas(156,43)
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);
var
LPropInfo: PPropInfo;
LValue: Variant;
begin
Assert(APropPath <> '', 'APropPath not assigned');
LPropInfo := tiGetPropInfo(AObject.ClassType, APropPath, @AObject);
if Assigned(LPropInfo) and Assigned(LPropInfo^.SetProc) then
begin
case tiGetTypeInfo(LPropInfo)^.Kind of
tkClass:
SetObjectProp(AObject, LPropInfo, TObject(Integer(APropValue)));
// ERROR OCCURS HERE -------^
tkEnumeration,tkBool:
[...snip...]
-----------------------------------------
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)));
This is correct _if_ APropvalue is a 64-bit integer on a 64-bit system. Better dump the whole procedure. Using variants is inviting problems. Michael. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal