<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Mo., 2. März 2020, 22:47:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the snippet below why isn't it an error to write to a field of the read-only property? I was hoping this would give me some type safety but it just writes to a temp variable and does nothing. Not very helpful if you ask me.<br>
<br>
<br>
=========================<br>
<br>
type<br>
TSheet = record<br>
m_tableSize: TVec2i;<br>
function GetTableSize: TVec2i;<br>
property TableSize: TVec2i read GetTableSize;<br>
end;<br>
<br>
var<br>
sheet: TSheet;<br>
begin<br>
// why isn't this an error?<br>
sheet.x := 1;<br>
end;<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I assume you mean "sheet.TableSize.x"? Otherwise your example makes no sense... </div><div dir="auto"><br></div><div dir="auto">In that case: you are working on a temporary copy of the record. It does not affect the TSheet instance anymore (that's essentially the same reason why C operators or var parameters are not allowed for properties). </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>