Question

I'm using Delphi XE3, and trying to create a massaging application same as outlook type, but when I try to load the Tscroll box with data about 2000 record it's getting so slow!

How can outlook scrolbox hold that much of data without being slow or flickering when scrolling ?

This is my code below to fill the scroll box with panels which later will contain information.

procedure TForm1.IdThreadComponent1Run(Sender: TIdThreadComponent);
var i: integer;
Pnl : TPanel;

begin
  for i := 1 to 2000 do
    begin
      Pnl := TPanel.Create(Self);
      Pnl.Align := alTop;
      Pnl.parent := scrollbox1;
      Pnl.Caption := inttostr(i);
    end;
   IdThreadComponent1.Active := false;
end;
Was it helpful?

Solution

You are using a windowed control (TPanel) for your content. The more instances you create, the more OS resources are allocated and managed, and the slower things get over time. To avoid all of that overhead, use a graphical control instead, such as TLabel or even create your own component derived from TGraphicControl.

Alternatively, you can switch to a different windowed control that is designed for displaying lots of data, such as a TListView or TListBox running in virtual mode. Then you don't need the TScrollBox anymore.

BTW, the TIdThreadComponent.OnRun event handler runs in the context of a worker thread, not the main thread. The code you showed is not thread-safe. The TPanel code needs to be executed in the context of the main thread via TThread.Synchronize(), TIdSync, or any other inter-thread synchronization mechanism. In which case, the TIdThreadComponent code you showed becomes useless as a thread and could be replaced with a simple timer or custom window message instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top