[fpc-pascal] type helpers
Sven Barth
pascaldragon at googlemail.com
Fri Jan 11 14:27:13 CET 2019
Am Fr., 11. Jan. 2019, 11:24 hat Mattias Gaertner via fpc-pascal <
fpc-pascal at lists.freepascal.org> geschrieben:
> Hi,
>
> A type helper can change Self.
> I wondered how FPC 3.3.1 handles properties and got some
> unexpected results. Is this by design, a bug, or not-yet-implemented?
>
> {$mode objfpc}{$modeswitch typehelpers}
> type
> TIntHlp = type helper for word
> procedure DoIt;
> end;
>
> TBig = class
> strict private
> FW: word;
> procedure SetW(const AValue: word);
> public
> property W: word read FW write SetW;
> end;
>
> var b: TBird;
>
> procedure TBig.SetW(const AValue: word);
> begin
> // not called by type helper
> writeln('TBig.SetW');
> end;
>
> procedure TIntHlp.DoIt;
> begin
> writeln('TIntHlp.DoIt START ',Self,' w=',b.w);
> Self:=4; // changes b.FW directly
> writeln('TIntHlp.DoIt END ',Self,' w=',b.w);
> end;
>
> begin
> b:=TBig.Create;
> b.w.DoIt;
> end.
>
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.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190111/31bc00fc/attachment.html>
More information about the fpc-pascal
mailing list