Typinfo incompatibilities between FPC and Delphi

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Typinfo incompatibilities between FPC and Delphi

Kenneth Cochran
I'm attempting to port GExperts from Delphi to Lazaurus and noticed the definition of TPropInfo differs from Delphi's.

In FPC's TPropInfo the PropType field is PTypeInfo whereas in Delphi it is PPTypeInfo. I'm not sure what is actually gained by this extra level of indirection but it exists none the less.

Are there any plans to update TPropInfo to be compatible with Delphi or do I need to  wrap dependent code with compiler conditionals?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Sven Barth-2
On 31.05.2014 05:53, Kenneth Cochran wrote:
> I'm attempting to port GExperts from Delphi to Lazaurus and noticed the
> definition of TPropInfo differs from Delphi's.
>
> In FPC's TPropInfo the PropType field is PTypeInfo whereas in Delphi it
> is PPTypeInfo. I'm not sure what is actually gained by this extra level
> of indirection but it exists none the less.
>
> Are there any plans to update TPropInfo to be compatible with Delphi or
> do I need to  wrap dependent code with compiler conditionals?

There are no plans as we have to stay compatible with our own old
codebases as well. You'll need to use compiler conditionals.

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Vincent Snijders-3



2014-05-31 11:48 GMT+02:00 Sven Barth <[hidden email]>:
On <a href="tel:31.05.2014%2005" value="+13105201405" target="_blank">31.05.2014 05:53, Kenneth Cochran wrote:
I'm attempting to port GExperts from Delphi to Lazaurus and noticed the
definition of TPropInfo differs from Delphi's.

In FPC's TPropInfo the PropType field is PTypeInfo whereas in Delphi it
is PPTypeInfo. I'm not sure what is actually gained by this extra level
of indirection but it exists none the less.

Are there any plans to update TPropInfo to be compatible with Delphi or
do I need to  wrap dependent code with compiler conditionals?

There are no plans as we have to stay compatible with our own old codebases as well. You'll need to use compiler conditionals.

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/

Vincent

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Sven Barth-2
On 31.05.2014 11:57, Vincent Snijders wrote:

>
>
>
> 2014-05-31 11:48 GMT+02:00 Sven Barth <[hidden email]
> <mailto:[hidden email]>>:
>
>     On 31.05.2014 05 <tel:31.05.2014%2005>:53, Kenneth Cochran wrote:
>
>         I'm attempting to port GExperts from Delphi to Lazaurus and
>         noticed the
>         definition of TPropInfo differs from Delphi's.
>
>         In FPC's TPropInfo the PropType field is PTypeInfo whereas in
>         Delphi it
>         is PPTypeInfo. I'm not sure what is actually gained by this
>         extra level
>         of indirection but it exists none the less.
>
>         Are there any plans to update TPropInfo to be compatible with
>         Delphi or
>         do I need to  wrap dependent code with compiler conditionals?
>
>
>     There are no plans as we have to stay compatible with our own old
>     codebases as well. You'll need to use compiler conditionals.
>
>
> 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/

No, that is exactly the point. Compare the declaration of TPropInfo in
Delphi and FPC:

http://docwiki.embarcadero.com/Libraries/XE3/en/System.TypInfo.TPropInfo
http://www.freepascal.org/docs-html/rtl/typinfo/tpropinfo.html

In Delphi you have PropType as PPTypeInfo while in FPC you have PTypeInfo.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Maciej Izak
In reply to this post by Kenneth Cochran
In FPC's TPropInfo the PropType field is PTypeInfo whereas in Delphi it is PPTypeInfo. I'm not sure what is actually gained by this extra level of indirection but it exists none the less.


By Barry Kelly in comment :) :


"all typeinfo fixups - pointers from one blob of typeinfo to another - are of type PPTypeInfo, not PTypeInfo, to handle the dynamic linking case. In the case of static linkage, there needs to be an intermediate pointer for the convention to work, and part of the typeinfo itself makes as much sense as any. That is to say, it's not there for the linker; it's there because of the convention, and the convention is there because of dynamic linking, which is done the way it is to maximize potential for page sharing."

Regards,
Maciej Izak (hnb)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Marco van de Voort
In our previous episode, Maciej Izak said:

> By Barry Kelly in comment :) :
>
> http://stackoverflow.com/questions/3443097/what-is-the-identity-pointer-before-a-ttypeinfo-there-for
>
> "all typeinfo fixups - pointers from one blob of typeinfo to another - are
> of type PPTypeInfo, not PTypeInfo, to handle the dynamic linking case. In
> the case of static linkage, there needs to be an intermediate pointer for
> the convention to work, and part of the typeinfo itself makes as much sense
> as any. That is to say, it's not there for the linker; it's there because
> of the convention, and the convention is there because of dynamic linking,
> which is done the way it is to maximize potential for page sharing."

Thanks, I added it to the wiki:

http://wiki.freepascal.org/packages#Details
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Graeme Geldenhuys-6
In reply to this post by Vincent Snijders-3
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/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Sven Barth-2

Am 03.06.2014 10:26 schrieb "Graeme Geldenhuys" <[hidden email]>:
>
> 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.
>

If one uses a helper function like you did then it's indeed not as bad, but if one doesn't...

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

Out of curiosity: is this helper declared as "inline"? Would get rid of the call completely in both Delphi and FPC...

>
> I've also introduced an enhanced GetPropInfo() with a signature as follows:
>
> function tiGetPropInfo(AClass: TClass; PropPath: string; PInstance:
> Pointer): PPropInfo;

Might also profit from a declaration as "inline" :)

Yours,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Graeme Geldenhuys-6
On 2014-06-03 10:08, Sven Barth wrote:
>
> If one uses a helper function like you did then it's indeed not as bad,
> but if one doesn't...

Indeed. :) I find it is often amount managing readability of code. The
application developer doesn't need to worry to much about the difference
between platforms - if you give them the right tools. After all, that is
what FPC is all about.


> Out of curiosity: is this helper declared as "inline"? Would get rid of
> the call completely in both Delphi and FPC...

A very good suggestion thanks. I'll apply that immediately.


>> I've also introduced an enhanced GetPropInfo() with a signature as
> follows:
>>
>> function tiGetPropInfo(AClass: TClass; PropPath: string; PInstance:
>> Pointer): PPropInfo;
>
> Might also profit from a declaration as "inline" :)

This one might not work as inline, as it is much more involved. Also
note the PropPath property. tiOPF can handling calls like:

  tiGetPropInfo(MyObject, 'Contact.Address.PostCode', ...)

It will iterate through the MyObject.Contact.Address.PostCode
properties, obviously doing NULL checks along the way. Hence the name
"PropPath" (property path).


Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Sven Barth-2
On 08.06.2014 17:03, Graeme Geldenhuys wrote:

>>> I've also introduced an enhanced GetPropInfo() with a signature as
>> follows:
>>>
>>> function tiGetPropInfo(AClass: TClass; PropPath: string; PInstance:
>>> Pointer): PPropInfo;
>>
>> Might also profit from a declaration as "inline" :)
>
> This one might not work as inline, as it is much more involved. Also
> note the PropPath property. tiOPF can handling calls like:
>
>    tiGetPropInfo(MyObject, 'Contact.Address.PostCode', ...)
>
> It will iterate through the MyObject.Contact.Address.PostCode
> properties, obviously doing NULL checks along the way. Hence the name
> "PropPath" (property path).

Ah ok. I thought it was also a more simpler wrapper call. Then not :P

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Sven Barth-2
In reply to this post by Marco van de Voort
On 31.05.2014 15:45, Marco van de Voort wrote:

> In our previous episode, Maciej Izak said:
>> By Barry Kelly in comment :) :
>>
>> http://stackoverflow.com/questions/3443097/what-is-the-identity-pointer-before-a-ttypeinfo-there-for
>>
>> "all typeinfo fixups - pointers from one blob of typeinfo to another - are
>> of type PPTypeInfo, not PTypeInfo, to handle the dynamic linking case. In
>> the case of static linkage, there needs to be an intermediate pointer for
>> the convention to work, and part of the typeinfo itself makes as much sense
>> as any. That is to say, it's not there for the linker; it's there because
>> of the convention, and the convention is there because of dynamic linking,
>> which is done the way it is to maximize potential for page sharing."
>
> Thanks, I added it to the wiki:
>
> http://wiki.freepascal.org/packages#Details

I have the feeling that the introduction of dynamic packages in FPC
*will* require us to change our current RTTI from PTypeInfo to
PPTypeInfo... :/

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Typinfo incompatibilities between FPC and Delphi

Maciej Izak

I have the feeling that the introduction of dynamic packages in FPC *will* require us to change our current RTTI from PTypeInfo to PPTypeInfo... :/

Regards,
Sven

So better to do it earlier rather than later ;P 
 
Regards,
Maciej Izak (hnb)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal