Recent

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

lucamar

  • Hero Member
  • *****
  • Posts: 4219
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/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018