[fpc-pascal] Better usage of "with"

Sven Barth pascaldragon at googlemail.com
Thu Jun 14 14:26:26 CEST 2018


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Do., 14. Juni 2018,
11:59:

>
>
> > On Jun 14, 2018, at 4:44 PM, Ryan Joseph <ryan at thealchemistguild.com>
> wrote:
> >
> > Something I tried was using properties like this but it didn’t work. Is
> that something properties could do? It feels like they should be able to
> reach into records fields that since everything is known to the property as
> time of declaration.
> >
> > property Position: TVec2D read entity^.position;
>
> I just did a test and found out property does indeed access record fields
> (that’s great to know) but when I made it a pointer that’s when it broke.
> Why not make properties do this?
>
> type
>         TEntity = record
>                 position: TVec2;
>         end;
>         TEntityPtr = ^TEntity;
>
> type
>         TDoor = record
>                 entity: TEntityPtr;
>                 state: boolean;
>                 property position: TVec2 read entity^.position;
>         end;
>

Because one needs to be able to represent the properties in the RTTI.
Without pointers all that is needed to access the property from code is an
offset. With pointers you'd need to add where dereferences are required
especially as the "path" to the final field could be more complex (e.g.
Field1^.Field3.Field1.Field5^.FinalField).
For this the solution is a getter function that you can also declare as
"inline".

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180614/d433cc68/attachment.html>


More information about the fpc-pascal mailing list