[fpc-pascal] Typinfo incompatibilities between FPC and Delphi

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Mon Jun 2 00:05:23 CEST 2014


On 2014-05-31 10:57, Vincent Snijders wrote:
> I think it is possible to write code without $ifdef (valid for Delphi
> and FPC) if you use the typeinfo unit to extract the information.
> http://www.freepascal.org/docs-html/rtl/typinfo/

Almost, but not quite. Good news is, it is not nearly as bad as Sven
makes it out to be.

The tiOPF project uses RTTI extensively. I have written a lot of that
code, and with the following helper function, I could eliminate a lot of
IFDEF's between FPC and Delphi RTTI behaviour.


function tiGetTypeInfo(PropInfo: PPropInfo): PTypeInfo;
begin
{$IFDEF FPC}
  Result := PropInfo^.PropType;
{$ELSE}
  Result := PropInfo^.PropType^;
{$ENDIF}
end;

I've also introduced an enhanced GetPropInfo() with a signature as follows:

function tiGetPropInfo(AClass: TClass; PropPath: string; PInstance:
Pointer): PPropInfo;


To see the complete code, take a look at the Core/tiRTTI.pas unit in the
tiOPF's 'tiopf2' branch.

That unit is also fully unit tested. Tests and usage examples can be
found in the following unit:

  UnitTests/Tests/tiRTTI_TST.pas


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/



More information about the fpc-pascal mailing list