Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting set of controls at runtime is extremely slow

We have a point-of-sale application and in this application we have a scrollbox container. If the seller selects a product, then a new product row is created and inserted into the scrollbox. The product row component is a frame - textboxes, buttons and labels in it.

But here's a little problem by inserting this product row control into the scrollbox at runtime. It's slow. I can see how selecting product draws edittext components slowly into the scrollbox.

I tried to set the components' visibility to false before ScrollBox.InsertControl and enabling it after, but it doesn't help speed up things very much. Also I read about DisableAlign/EnableAlign thing, but I don't know exactly where I have to put this line of code.

How can I speed up inserting this custom component into the form's scrollbox container?

like image 657
evilone Avatar asked Dec 17 '22 13:12

evilone


1 Answers

TScrollBox doesn't have BeginUpdate/EndUpdate, but you can get the same effect using WM_SETREDRAW messages. I would probably avoid more heavy handed 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;
like image 62
Bruce McGee Avatar answered Dec 28 '22 06:12

Bruce McGee