[Lazarus] Forward declare (modern) records [was: Re: "global" operator overloading]

ListMember listmember at letterboxes.org
Wed Feb 27 13:22:18 CET 2013


On 2013-02-27 13:28, Sven Barth wrote:
> Am 27.02.2013 10:51, schrieb Michael Schnell:
>> On 02/26/2013 04:18 PM, Sven Barth wrote:
>>> You CAN NOT have the record used as a field inside itself,
>>
>> Using a pointer to this type within a record does make a lot of sense 
>> for creating linked lists. I do this all the time in "C".
> This is not what is being talked about. It's about defining record 
> types that use each other in their properties or functions without 
> defining a pointer type.

Precisely.

Referring to your other post, you gave this example:

=== 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 ===

While it does capture the idea, let me make it more detailed/clearer.

What I am proposing/suggesting is like this:

=== example begin ===

type
   SomeType1 = record;
   SomeType2 = record;

   SomeType1 = record
     // ...
     property SomeProperty: SomeType2 read *GetSomeType2* write 
*SetSomeType2*;
   end;

   SomeType2 = record
     // ...
     property SomeProperty: SomeType1 read *GetSomeType1* write 
*SetSomeType1*;
   end;

=== example end ===

You will notice that I have NOT used any fields that were forward declared.

I only (wish to) use the forward declared record types in 
methods/getters/setters/properties.

Correct me if I am wrong, but this way we can eliminate the possiblity 
of introducing infinite recursion (that would arise if we used forward 
declared record types as fields).

Is there still any logical flaw in this?






More information about the Lazarus mailing list