[fpc-devel] Language extension: absolute for classes

Micha Nelissen micha at neli.hopto.org
Sun Oct 1 22:10:09 CEST 2006


Michael Van Canneyt wrote:
>> is to be written in a certain format, so you tell the compiler that it
>> is like that. Why is this a hack ?
> 
> Because you do a typecast just as if you would override a property using a
> read specifier and do the typecast there. Just the typecast is disguised 
> as an 'absolute'...

In this case I'm doing a typecast because the compiler is too 'stupid',
so the motivation for the typecast is different than in the general case.

I have been thinking of another way, but it's more involved, but also
'more correct'. The class A would specify for the 'Field: F' that it has
an overrideable type, maybe keyword 'virtual' or so. The compiler will
store the type in the RTTI of the class. Then, B can override the type,
and the compiler will rewrite the needed type (G) into the RTTI. Then at
runtime, whenever an assignment to A.Field is done, the compiler will
generate code that retrieves from the RTTI the 'needed' type, and will
check the type of the rightside expression to that needed type, like
'as' operator does.

Micha



More information about the fpc-devel mailing list