[fpc-pascal] Better usage of "with"

Ryan Joseph ryan at thealchemistguild.com
Thu Jun 14 14:43:38 CEST 2018



> On Jun 14, 2018, at 7:19 PM, Martin <fpc at mfriebe.de> wrote:
> 
> 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.

yeah so you wouldn’t design your data like that. :) There’s always a potential for naming conflicts but some how we manage them.

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

That’s not what you’d do though. Like my response above this assumes you actually know what you’re doing and you aren’t going to trash memory.


Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list