[Lazarus] Forward declare (modern) records [was: Re: "global" operator overloading]
Sven Barth
pascaldragon at googlemail.com
Tue Feb 26 18:38:59 CET 2013
On 26.02.2013 18:22, Jürgen Hestermann wrote:
>
> Am 2013-02-26 16:15, schrieb ListMember:
>>
>> Is it possible to forward declare records the way we can with classes?
>>
>
> Well, I know that you can do something like this:
>
> PTreeType = ^TreeType;
> TreeType = record
> ...;
> ...;
> Dirs : PListType;
> end; { of record }
>
> You can see that "TreeType" is used in the first line although it is not
> (yet) defined.
> As long as you declare the type within the same "Type" section the
> compiler swallows it.
He wants to have this supported:
=== example begin ===
type
SomeType1 = record;
SomeType2 = record;
SomeType1 = record
// ...
property SomeProperty: SomeType2 read ... write ...
end;
SomeType2 = record
// ...
property SomeProperty: SomeType1 read ... write ...
end;
=== example end ===
Just in case you aren't up to date with FPC's supported language,
Jurgen, the following works in FPC out of Delphi compatibility since
2.6.0 (though it needs {$modeswitch advancedrecords} in non-Delphi modes):
=== example begin ===
type
SomeType = record
// ...
property SomeProperty: SomeType read ... write ...
end;
=== example end ===
What still doesn't work (and will never work [and doesn't work in Delphi
either :P ]) is this:
=== example begin ===
type
SomeType = record
SomeField: SomeType;
end;
=== example end ===
Regards,
Sven
More information about the Lazarus
mailing list