Recent

Author Topic: Change a property of Canvas.TextStyle directly  (Read 3663 times)

lucamar

  • Hero Member
  • *****
  • Posts: 2147
Re: Change a property of Canvas.TextStyle directly
« Reply #15 on: November 30, 2018, 05:49:20 pm »
My understanding:
Canvas.Textstyle returns a Record, NOT a Object.
If a function's return value is a Record, FPC returns a COPY of the original one, i.e. a copy of Canvas.FTextStyle in this case, Not a reference to the Canvas.FTextStyle itself.
So if we write:
Code: Pascal  [Select]
  1. with Canvas.TextStyle do Alignment := taRightJustify;
It equals to:
Code: Pascal  [Select]
  1. tmp := Canvas.TextStyle;
  2. tmp.Alignment := taRightJustify;
That's meaningless, and apparently NOT what we want. So, it's reasonable that FPC forbids this behavior.
It can also explains someone reported that the assignment has no effect with lower version of FPC, although allowed.

But that's  not the case here:
* first, because there's no "function": it's accessing a field directly;
* second, because it's not a read-only property; and
* third, because using "with" effectively changes that field, as demonstrated in my test above

The bug is not that it can't be changed but that it gets changed when using a with construction.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.