[fpc-pascal] Better usage of "with"

Martin fpc at mfriebe.de
Thu Jun 14 14:19:45 CEST 2018


On 14/06/2018 13:43, Ryan Joseph wrote:
>
>> On Jun 14, 2018, at 5:18 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>>
>> If you only want that, why not use objects?
> The real reason Jon Blow proposed this syntax is because it allows you keep continuous arrays of memory which you can index into using struts.
> The fact it mimics multiple inheritance (something Pascal doesn’t have anyways) is just a bonus.


You can do that without the "with"
record TFoo
   Bar: TOtherRecord; // has a field abc
end;

The only thing is that you need to access the field by its fully 
qualified name Foo.Bar.abc, instead of Foo.abc.
Which is good, because you can have

record TFoo
   Bar: TOtherRecord; // has a field abc
   Other: TOtherRecord; // has a field abc
end;

and as with multiple inheritance "Foo.abc" would be ambiguous.

And as already was mentioned you can have properties to shortcut this.
But then the question came up why not:

record TFoo
   Bar: POtherRecord; // pointer
   property abc: xxx read Bar^.abc
end;

Well because abc may be nil. But then it is no longer "continuous memory"



More information about the fpc-pascal mailing list