[fpc-pascal] Empty record inside another record ?
Vincent Snijders
vsnijders at quicknet.nl
Tue Feb 19 09:21:30 CET 2008
Tiziano De Togni schreef:
> Florian Klaempfl ha scritto:
>> Skybuck Flying schrieb:
>>> One drawback of objects already discovered:
>>>
>>> Objects cannot have the same field identifiers.
>>
>> Indeed, especially if you want to win an obfuscation contest.
>
> ok, this is true for object type, but it should not be extended to class
> types. Look at this example taken from Delphi Help:
>
> type
> TAncestor = class
> Value: Integer;
> end;
>
> TDescendant = class(TAncestor)
> Value: string; // hides the inherited Value field
> end;
>
> var
> MyObject: TAncestor;
>
> begin
> MyObject := TDescendant.Create;
> // MyObject.Value := 'Hello!'; // error
> TDescendant(MyObject).Value := 'Hello!'; // works!
> end;
>
> it compiles correctly in Delphi (5 and 7) but FPC (v2.2.0 - compiled
> with Params Values=" -S2cdgi -OG1 -gl -WG -vewnhi") still says
> that there is a duplicate identifier "Value"...
>
> am I correct?
>
This is not allowed in {$mode objfpc}, because of the reasons Florian memtioned. It
is allowed in {$mode delphi}.
Vincent
More information about the fpc-pascal
mailing list