[fpc-devel] RFC: Delphi style class helpers

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Dec 21 00:16:56 CET 2010


On 20 Dec 2010, at 21:37, Sven Barth wrote:

> I have taken the time to implement a first version of Delphi's class helpers. Thanks to Jonas' code for Objective C categories it was a rather easy to get that working.

Note that Delphi-style class helpers have several limitations that still have to be added to your patch:
a) from http://docwiki.embarcadero.com/RADStudio/2010/en/Class_and_Record_Helpers : "You can define and associate multiple helpers with a single type. However, only zero or one helper applies in any specific location in source code. The helper defined in the nearest scope will apply. Class or record helper scope is determined in the normal Delphi fashion (for example, right to left in the unit's uses clause)." -- In Objective-C, there is no limit on the number of categories for a class that applies at the same time.
b) afaik, Delphi class helpers cannot contain virtual methods, and definitely cannot override methods defined in a parent class (the used VMT is that of the helped class, so no additions/changes to the class that require VMT changes are allowed or even possible)

> - should class helpers be able to be instantiated or even referenced in any way? (including forward declarations)

No. They are not first class entities, they just add a bunch of method declarations to the scope of the extended class.

> - should class helpers be allowed to override/reintroduce methods?

Definitely no override. I don't know about reintroduce.

> - should class helpers be able to extend other class helpers (as class helpers are implemented as child classes of the extended class this might currently be possible)?

No, that does not make any semantic sense. How they are implemented in the compiler is irrelevant.

> - should abstract methods be forbidden?

Yes, since
a) they are virtual
b) even if it were possible to have virtual methods, there would be no way to override them with implementations that do something (since you cannot inherit from a class helper)


Jonas




More information about the fpc-devel mailing list