Recent

Author Topic: ListView can't measure TextWidth after second reload (and all loads after that)  (Read 2008 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 258
ListView1.Clear;
Load items
and it works, can measure TextWidth
again ListView1.Clear;
Load items
and:
Code: Pascal  [Select][+][-]
  1. TmpString :=  ListView1.Items.Item[i].SubItems[TmpInt-1];// I can see on breakpoint  it is 'something'
  2. TmpInt1 := ListView1.Canvas.TextWidth(TmpString); // gives me 0  
  3.  

EDIT: If I replace ListView1.Canvas with Form1.Canvas to measure text width, that "solves problem", but that is not it.
Just proof that something goes wrong with ListView1.Canvas.TextWidth
« Last Edit: July 28, 2016, 04:55:52 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
You don't say what the context of your call is. Is your listview fully loaded and parented at the moment of the call?

The main message loop is not re-entrant, so repeated calls within a single context can go awry if system or LCL messages have not had time to be received and responded to.
Sometimes a call to
  ProcessMessages;
helps.
Other times you have to resort to Application.QueueAsyncCall(), or re-design your program logic.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
The listview control (not the Lazarus component, but the Windows API control) under Windows has that behavior by default.
Even in other programming languages this needs to be resolved programmatically.

What is your platform? Os? Version? Laz version and FPC version?
Specialize a type, not a var.

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 258
lazarus-1.6.0-fpc-3.0.0-win64
win7 Pro SP1

Logic is:
1. Have list box with tables from db
2.click on it and fill ListView with list of columns and stuff from selected table.

So, Application.ProcessMessages; should not do any difference, since I can't click fast enough and I don't, to reload faster than previos process ends, only few items are cleared/added to ListView for each refill.
« Last Edit: July 28, 2016, 10:54:58 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018