Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-05

Typinfo incompatibilities between FPC and Delphi

12 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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?
Sven Barth
to Kenneth Cochran
Kenneth Cochran wrote 9 lines
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

Vincent Snijders
to Sven Barth

2014-05-31 11:48 GMT+02:00 Sven Barth :

Show quoted text 16 lines
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.

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

Sven Barth
to Vincent Snijders
Vincent Snijders wrote 30 lines
2014-05-31 11:48 GMT+02:00 Sven Barth < >: 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

Maciej Izak
to Kenneth Cochran: I'm attempting to port GExperts from Delphi to Lazaurus and noticed the definition of…
Show quoted text 6 lines
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 :) :

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."

Regards,
Maciej Izak (hnb)

Marco van de Voort
to Maciej Izak

In our previous episode, Maciej Izak said:

Show quoted text 11 lines
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

Graeme Geldenhuys
to Vincent Snijders: 2014-05-31 11:48 GMT+02:00 Sven Barth : I think it is possible to write code without…
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/
Sven Barth
to Graeme Geldenhuys

Am 03.06.2014 10:26 schrieb "Graeme Geldenhuys" <

Show quoted text 10 lines
: 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...

Show quoted text 8 lines
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

Graeme Geldenhuys
to Sven Barth
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.

Show quoted text 7 lines
> 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/
Sven Barth
to Graeme Geldenhuys
Graeme Geldenhuys wrote 16 lines
>> 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

Sven Barth
to Marco van de Voort: In our previous episode, Maciej Izak said: Thanks, I added it to the wiki:…
Marco van de Voort wrote 16 lines
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

Maciej Izak
to Sven Barth
Show quoted text 6 lines
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)