[Lazarus] How to fix slow screen refresh of TListbox?

Bo Berglund bo.berglund at gmail.com
Fri Nov 11 16:29:31 CET 2022


I am using a TListbox component on a form for displaying debug data arriving
over a serial line at 115200 baud.
The data are a set of MQTT telegram texts which arrive in packets of about 40
lines each time (once per 10 seconds).
I add them to the listbox as follows:

procedure THanSimulatorMain.OnRxData(Sender: TObject; const Data: TBytes);
var
  len, oldlen: integer;
  DataTxt: AnsiString;
begin
  len := Length(Data); //Incoming packet
  oldlen := Length(DataBuffer);
  SetLength(DataBuffer, oldlen + len);
  Move(Data[0], DataBuffer[oldlen], len);
  SetLength(DataTxt, Length(DataBuffer));
  Move(DataBuffer[0], DataTxt[1], Length(DataBuffer));
  lbxRxData.Items.Text := DataTxt;  //Add the text to the list
  lbxRxData.ItemIndex := lbxRxData.Items.Count -1; //To make it visible
end;

DataBuffer is a global TBytes container where the incoming data are stuffed as
they arrive (it grows during the session).
You see that the buffer contains the complete log history from the start...

I have noticed that after a while the display becomes very sluggish when data
arrives and I think that is due to the way the component operates.

Now I wonder if there is some way to do as I did when I worked in Delphi with
TListView objects, where I could use the BeginUpdate and EndUpdate calls to make
all screen updates wait until it was all put in place.
This was MUCH faster!

But I can not find a BeginUpdate on the TListBox object, only BeginUpdateBounds,
which does not tell me much....

Any suggestions?


-- 
Bo Berglund
Developer in Sweden



More information about the lazarus mailing list