Reputation: 22740
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?
Upvotes: 4
Views: 3330
Reputation: 15334
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;
Upvotes: 11
Reputation: 43669
Normally, a control adding to a container takes very little time. There's a high probability this has something to do with the creation of the control rather the insertion.
Upvotes: 1
Reputation: 4353
Try disabling screen updates when adding controls and enable screen update when done in a try-finally routine. Then the screen doesn't have to update for each separate control but just once, when all controls are placed.
Upvotes: 0