<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Am Fr., 11. Jan. 2019, 11:24 hat Mattias Gaertner via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> geschrieben:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
A type helper can change Self.<br>
I wondered how FPC 3.3.1 handles properties and got some<br>
unexpected results. Is this by design, a bug, or not-yet-implemented?<br>
<br>
{$mode objfpc}{$modeswitch typehelpers}<br>
type<br>
TIntHlp = type helper for word<br>
procedure DoIt;<br>
end;<br>
<br>
TBig = class<br>
strict private<br>
FW: word;<br>
procedure SetW(const AValue: word);<br>
public<br>
property W: word read FW write SetW;<br>
end;<br>
<br>
var b: TBird;<br>
<br>
procedure TBig.SetW(const AValue: word);<br>
begin<br>
// not called by type helper<br>
writeln('TBig.SetW');<br>
end;<br>
<br>
procedure TIntHlp.DoIt;<br>
begin<br>
writeln('TIntHlp.DoIt START ',Self,' w=',b.w);<br>
Self:=4; // changes b.FW directly<br>
writeln('TIntHlp.DoIt END ',Self,' w=',b.w);<br>
end;<br>
<br>
begin<br>
b:=TBig.Create;<br>
b.w.DoIt;<br>
end.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">This is by design. In this case DoIt is called on a temp variable that gets its value from b.w, the value of b.FW does not change (same reason why the C operators do not work on properties). Same happens with constants btw: Word(42).DoIt will work as well. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>