[fpc-devel] Re: RFC: Delphi style class helpers
Sven Barth
pascaldragon at googlemail.com
Wed Dec 22 09:00:20 CET 2010
Paul Ishenin wrote:
> 21.12.2010 16:20, Sven Barth wrote:
>>> http://docwiki.embarcadero.com/RADStudio/en/E2358_Class_constructors_not_allowed_in_class_helpers_(Delphi)
>>>
>>
>> As we don't have them yet...
>
> we have.
And here I thought that I'm closely following FPC development... that
must have slipt my attention. How embarrassing. -.-
Paul Ishenin wrote:
> I have attached few tests which answers to most of your questions.
Thank you for the tests. They indeed solved some questions, but some are
still left.
Would you please test the following:
- identifier visibility if class helper and extended class reside in
different units (because I can't believe that a helper can access
private members while a derived class can't)
- can overloaded methods be defined? (e.g. class contains "Test(a:
String);" and helper contains "Test(a: Integer);")
- what happens if you define a method in the helper that has the same
name as a virtual method in the extended class (without "override" of
course ^^)
- is a class helper method used in a derived class if the derived class
does not contain a method with the same name?
- class helper and class in two different units, both containing a
method with the same name. which method get's called if the unit with
the class is used before the unit with the class helper in the main program?
- can class helpers have fields and if so is their value saved somehow?
- can class helpers extend interfaces?
- can a class helper reintroduce a virtual method from the extended class?
Jonas Maebe wrote:
> This feature (virtual class helper methods) might be part of the reason why only one class helper can be used, depending on how they handle the class helper VMTs. You start getting some kind of multiple inheritance with multiple VMTs in terms of figuring out which class helper VMT to pass when calling one class helper method from another class helper.
>
> Take this example:
[illustrative example]
This could indeed be the reason why only one class helper is used. So
either we follow Delphi compatibility and allow virtual methods in class
helpers and forbidding the use of multiple class helpers or forbidding
virtual methods and allowing the use of multiple class helpers (although
I must admit that I don't yet know which other problems might come
around)...
So let me summarize what I know now:
- class helper syntax is the followingĖ
ClassHelperName = class helper[(BaseClassHelper)] for ExtendedClass
(...)
end;
BaseClassHelper must be a class helper for the same class.
- in "virtual; abstract;" and "override;" after methods of the extended
class generate an error, while "dynamic;" and "virtual;" are allowed
- "message" is allowed but in the end not accessable - should that be
forbidden in mode "objfpc"?
- only the first found class helper for a given class is used
- class helpers can not be used in forward declarations
- class helpers can not extend generic classes
- class helpers may not contain destructors
- class helpers may contain constructors, but these need to call the
inherited parameterless constructor without any argument as first
statement (regarding class constructors I need to read the article
linked by Jonas)
- class helpers hide methods with the same name in the ExtendedClass,
but not in derived classes - is this a good behavior? (in the current
test implementation a class helper method is only searched if no other
identifier is found)
Are those assumptions correct so far? Did I miss something we already know?
Maybe I should write a wiki page to have the "specification" saved
somewhere :)
Regards,
Sven
More information about the fpc-devel
mailing list