Recent

Author Topic: Label.Width not updated properly when Visible=False  (Read 4407 times)

FrankBKK

  • New Member
  • *
  • Posts: 31
Label.Width not updated properly when Visible=False
« on: June 21, 2021, 09:09:33 am »
What can I do that the Label.Width will be properly updated ?
lbYMax.AutoSize = True  - works correct with AutoSize = False !
I tried it with Refresh, Repaint, Invalidate, Application.ProcessMessages

Code: Pascal  [Select][+][-]
  1. sLabelText1 := lbYMax.Caption ;
  2. iLabelWidth1 := lbYMax.Width ;
  3.  
  4.     lbYMax.Caption := cbFCSYValue.Text + ' - ' + IntToStr(seFcsRangeYto.Value) ;
  5.  
  6. sLabelText2 := lbYMax.Caption ;
  7. iLabelWidth2 := lbYMax.Width ;
  8.  

Debugger Local Variables reports this:
Code: Pascal  [Select][+][-]
  1. sLabelText1='Y - 32768'
  2. sLabelText2='ABCDEFY - 32768'
  3. iLabelWidth1=48
  4. iLabelWidth2=48
  5.  
  6.  
« Last Edit: June 21, 2021, 04:38:48 pm by FrankBKK »

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Label.Width is wrong when AutoSize = True
« Reply #1 on: June 21, 2021, 09:55:31 am »
Cannot confirm

EDIT:
OS Win10-64
FPC3.2.0-32Bit
Laz2.0.12-32Bit
« Last Edit: June 21, 2021, 10:26:53 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Label.Width is wrong when AutoSize = True
« Reply #2 on: June 21, 2021, 09:58:52 am »
What is your OS/widgetset? IIRC some Ubuntu versions (gtk2?) have this issue.

FrankBKK

  • New Member
  • *
  • Posts: 31
Re: Label.Width is wrong when AutoSize = True
« Reply #3 on: June 21, 2021, 12:28:14 pm »

OS Win10-64
FPC3.2.0-32Bit
Laz2.0.12-32Bit

This problem only occurs when Label.AutoSize := True ;

On Label.AutoSize := False results are correct
 

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Label.Width is wrong when AutoSize = True
« Reply #4 on: June 21, 2021, 01:21:40 pm »
I have the same system by default and have never seen such an issue there. Please post a compilable (simple) project.

FrankBKK

  • New Member
  • *
  • Posts: 31
Re: Label.Width is wrong when AutoSize = True
« Reply #5 on: June 21, 2021, 03:18:04 pm »
I think I found the issue.

Please compile + run the attached mini project.

Click first on the button 'Wrong Position', then the 'All good' button. If you click again on 'Wrong Position' the label now shows correct.
The Label's right position is supposed to touch the button's left/right position.

Seems like Label.Visible := False  while changing the Caption  is the culprit  - on the first run the Width is not updated only on the following runs.

 

« Last Edit: June 21, 2021, 03:21:27 pm by FrankBKK »

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Label.Width is wrong when AutoSize = True
« Reply #6 on: June 21, 2021, 03:38:32 pm »
Your btWrong code works correctly in Delphi, so I think this should be considered to be a bug. On the other hand it is easy to fix (by setting the caption before hiding the labels). If there were a bugreport for it I hope that nobody would pick it up and try to fix it because setting the control size and AutoSizing are among the most complex tasks in the LCL, and there is a high risk that this fix would break something else

Just my two cents...

FrankBKK

  • New Member
  • *
  • Posts: 31
Re: Label.Width is wrong when AutoSize = True
« Reply #7 on: June 21, 2021, 04:37:53 pm »
Yep, agree - no need for a bug report - I was just not sure if it was me doing something stupid ... ;-)

 

TinyPortal © 2005-2018