Pasting a set of controls at run time is extremely slow

We have an application for sale, and in this application we have a scroll container. If the seller selects a product, a new product line is created and inserted into the scroll. The component of the product line is a frame - text fields, buttons and labels in it.

But here is a small problem by inserting this product line control into the temporary scroll pane. It is slow. I can see how product selection is slowly pulling edittext components into the scroll.

I tried setting the components visibilityto false before ScrollBox.InsertControland turning it on after, but this does not speed things up. I also read about DisableAlign / EnableAlign, but I do not know exactly where I should put this line of code.

How to speed up the insertion of this custom component into the scroll form container?

+3
source share
3 answers

TScrollBox does not have BeginUpdate / EndUpdate, but you can get the same effect using WM_SETREDRAW messages. I would probably avoid harder methods like LockWindowUpdate .

  SendMessage(ScrollBox1.Handle, WM_SETREDRAW, 0, 0);
  try
    // add controls to scrollbox
    // set scrollbox height
  finally
    SendMessage(ScrollBox1.Handle, WM_SETREDRAW, 1, 0);
    RedrawWindow(ScrollBox1.Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
  end;
+8
source

Typically, a control that is added to a container takes very little time. There is a high probability that this has something to do with the creation of the control, and not with the insert.

+1
source

Try disabling screen updates when adding controls and enabling screen updates when done in a try-finally program. Then, the screen should not be updated for each individual control, but only once, when all the controls are placed.

0
source

All Articles