Sign in Join

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

Mailing lists / fpc-devel / 2011-03

Class helper: small differences between FPC and Delphi

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Sven Barth

Hello together!

While cleaning up the tests a bit (splitting them in "class helper", "record helper" and "general" tests) I noticed two small differences in my implementation and that of Delphi.

1. Record helpers in Delphi don't support inheritance. In FPC they do and I believe (see point 2) that record helpers in Delphi could support that as well, but it's been disabled on purpose. I personally think that inheritance for record helpers increases their use, because you can work around the "one helper per type" problem by using inheritance.

So I will definitely keep that "feature" in, but the question is whether I should forbid this in mode Delphi...

2. In Delphi helpers are based on classes and in FPC they are a seperate type. I've choosen the later, because it has reduced the need for some checks and also simplified the code.
I noticed the difference when checking the RTTI parent reference of a class helper (I had already checked that it is of type tkClass, but haven't thought more about it): the result was that all helpers (class and record) inherit from a class TClassHelperBase which in turn inherits from TInterfacedObject.

As I honestly don't want to rebuild my entire implementation (now that I'm basically finished and everything works) I'm proposing the following clean - but Delphi incompatible - solution: I introduce a new RTTI kind tkHelper of which the helpers will be a type of. It will be similar to classes, but the parent of a not inherited helper will be Nil (I could add a reference to the extended type as well).

I believe that this won't have that much impact on Delphi code as RTTI of helper's shouldn't be used that often (at least a quick googling reveals that people mostly want to use the RTTI to see all helpers that apply to a type - which isn't possible).

Regards,
Sven

Reply by email

Jonas Maebe
to Sven Barth
Sven Barth wrote
1. Record helpers in Delphi don't support inheritance. In FPC they do and I believe (see point 2) that record helpers in Delphi could support that as well, but it's been disabled on purpose. I personally think that inheritance for record helpers increases their use, because you can work around the "one helper per type" problem by using inheritance. So I will definitely keep that "feature" in

I think you should ask for the reason on the Embarcadero forums before deciding that.

Jonas

Reply by email

waldo kitty
to Jonas Maebe
Jonas Maebe wrote 8 lines
On 25 Mar 2011, at 22:33, Sven Barth wrote: > 1. Record helpers in Delphi don't support inheritance. In FPC they do and I believe (see point 2) that record helpers in Delphi could support that as well, but it's been disabled on purpose. I personally think that inheritance for record helpers increases their use, because you can work around the "one helper per type" problem by using inheritance. > > So I will definitely keep that "feature" in I think you should ask for the reason on the Embarcadero forums before deciding that.

or at least disable it in delphi mode and then if delphi does actually support it, then enable it... hopefully there won't be any real differences if they do support it ;)

Reply by email

Florian Klaempfl
to Sven Barth: Hello together! While cleaning up the tests a bit (splitting them in "class helper",…
Sven Barth wrote 9 lines
2. In Delphi helpers are based on classes and in FPC they are a seperate type. I've choosen the later, because it has reduced the need for some checks and also simplified the code. I noticed the difference when checking the RTTI parent reference of a class helper (I had already checked that it is of type tkClass, but haven't thought more about it): the result was that all helpers (class and record) inherit from a class TClassHelperBase which in turn inherits from TInterfacedObject.

What does prevent you to mimic this behaviour?

Reply by email

Marco van de Voort
to Sven Barth: Hello together! While cleaning up the tests a bit (splitting them in "class helper",…

In our previous episode, Sven Barth said:

Show quoted text 5 lines
1. Record helpers in Delphi don't support inheritance. In FPC they do and I believe (see point 2) that record helpers in Delphi could support that as well, but it's been disabled on purpose. I personally think that inheritance for record helpers increases their use, because you can work around the "one helper per type" problem by using inheritance.

I though helpers were mostly static? How does the helped class know what exact instance is meant?

I do see that inheritance can help a bit with helpers that are mostly static, but intuitively I'd say that is not that useful.

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 9 lines
In our previous episode, Sven Barth said: > 1. Record helpers in Delphi don't support inheritance. In FPC they do > and I believe (see point 2) that record helpers in Delphi could support > that as well, but it's been disabled on purpose. I personally think that > inheritance for record helpers increases their use, because you can work > around the "one helper per type" problem by using inheritance. I though helpers were mostly static? How does the helped class know what exact instance is meant?

It's not for the helped class, and the result is still static since afaik virtual methods are not allowed for class helpers. Because only one class helper can be used for particular class at a time, if you want to enable both the routines of an existing helper and some extra routines in the current scope, you have to create a child of the existing helper and add those extra routines to this child. If you don't inherit from the existing helper then only the new routines will be available.

Jonas

Reply by email

Sven Barth
to Florian Klaempfl: What does prevent you to mimic this behaviour?
Florian Klaempfl wrote 12 lines
Am 25.03.2011 22:33, schrieb Sven Barth: > > 2. In Delphi helpers are based on classes and in FPC they are a seperate > type. I've choosen the later, because it has reduced the need for some > checks and also simplified the code. > I noticed the difference when checking the RTTI parent reference of a > class helper (I had already checked that it is of type tkClass, but > haven't thought more about it): the result was that all helpers (class > and record) inherit from a class TClassHelperBase which in turn inherits > from TInterfacedObject. What does prevent you to mimic this behaviour?

I hope you mean to only mimic this exact RTTI case...

I'd need to add a Delphi compatible "TClassHelperBase" class in system.pp and track its def like its done for "TObject", "IUnknown" and teh ObjC base def.

* technical prevention: none
* personal prevention: I'm personally not a big fan of those "compiler tracked defs" (although I already know that I need to add one when I'm going to implement attributes :( )

If you think it would be wiser to mimic the Delphi implementation, I will do so.
In my opinion though the difference should not concern too many people (*) and would lead to a cleaner way to decide whether a given type is a helper or a real class. Also I'd be able to add a "ExtendedTypeInfo" field which would contain the type the helper extends.

(*) a quick google search basically only revails Embarcadero's thin documentation about that class (
http://docwiki.embarcadero.com/VCL/2010/en/System.TClassHelperBase ) and the class helper threads on this mailing list

Regards,
Sven

Reply by email

Sven Barth
to waldo kitty: or at least disable it in delphi mode and then if delphi does actually support it, then…
waldo kitty wrote 19 lines
On 3/25/2011 17:57, Jonas Maebe wrote: > > On 25 Mar 2011, at 22:33, Sven Barth wrote: > >> 1. Record helpers in Delphi don't support inheritance. In FPC they do >> and I believe (see point 2) that record helpers in Delphi could >> support that as well, but it's been disabled on purpose. I personally >> think that inheritance for record helpers increases their use, >> because you can work around the "one helper per type" problem by >> using inheritance. >> >> So I will definitely keep that "feature" in > > I think you should ask for the reason on the Embarcadero forums before > deciding that. or at least disable it in delphi mode and then if delphi does actually support it, then enable it... hopefully there won't be any real differences if they do support it ;)

That was my question after all... allowing it for ObjFPC but disallowing it for mode Delphi.

Nevertheless I opened a thread here:
https://forums.embarcadero.com/thread.jspa?threadID=51684&stqc=true

Regards,
Sven

Reply by email

Sven Barth
to Paul Ishenin
Paul Ishenin wrote 8 lines
27.03.2011 6:34, Sven Barth wrote: > That was my question after all... allowing it for ObjFPC but > disallowing it for mode Delphi. > > Nevertheless I opened a thread here: > https://forums.embarcadero.com/thread.jspa?threadID=51684&stqc=true What if you define a class helper for a record? It is allowed to inherit a class helper for a record?

At least since Delphi XE it is forbidden to define class helpers for records and vice versa.

Regards,
Sven

Reply by email