[fpc-pascal] Class field property access

Sven Barth pascaldragon at googlemail.com
Mon Jun 3 17:13:12 CEST 2019


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Mo., 3. Juni 2019,
16:36:

> I found a restriction in properties which is a little disappointing. I get
> there’s probably some objective of safety but Pascal is a direct memory
> access language so I don’t understand why properties have this unique
> restriction when I could do the same thing using functions (pointers can’t
> be dereferenced in properties either). Shouldn’t I as the programmer get to
> decide whether the property is safe or not based upon when I call it?
>
> type
>   TB = class
>     x: integer;
>   end;
>
> type
>   TA = class
>     private
>       b: TB;
>     public
>       property x: integer read b.x;     // ERROR: Must be a record/object
> type
>   end;
>

The b field could be Nil and the class might not provide any functionality
to check for that. In addition to that it's an additional indirection while
records/objects merely require an offset.

Regards,
Sven

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


More information about the fpc-pascal mailing list