If you use a Delphi component like a ListBox, Memo, TreeList, ListView,... and
you add or modify a lot of items (lines, nodes,...), the component's performance
becomes very slow. This is due to the fact that after each change, it is redrawn
on the screen.
Thus, modifying 10000 items of a ListBox causes 10000 redraws, and that takes from several seconds to several minutes, depending on the computer's speed and the complexity of the process. Imagine how slow it can become if the process involves inserting, deleting, modifying and swapping many thousands of items.
But you can speed up things enormously with the following tip:
Here's a simple source code example for using this technique with a ListBox containing 10000 items:
ListBox1.Items.BeginUpdate; for i := 1 to 10000 do ListBox1.Items.Add('abcd'); ListBox1.Items.EndUpdate;
To give you an idea of the improvement, we timed the code above (your PC may be faster or slower):
Here's a source code example for using the technique with a Memo containing 5000 lines:
Memo1.Lines.BeginUpdate; for i := 1 to 5000 do Memo1.Lines.Add('abcd'); Memo1.Lines.EndUpdate;
» without BeginUpdate/EndUpdate: