00 Votes

Delphi/Lazarus: Why should I use BeginUpdate and EndUpdate?

Question by Guest | 2016-01-10 at 23:37

I have often seen code examples for Delphi and Lazarus applications in which the commands BeginUpdate and EndUpdate have been used. For example when filling a ListBox or ListView with items, but also when adding some lines to a Memo.

Can someone explain to me why this is necessary and why this is used so often? I have tried it and it is also working without those functions. The program should even automatically know that there is now a new item coming, so why do you have to tell the application this via BeginUpdate at the beginning and EndUpdate at the end?

ReplyPositiveNegative
Avatar
3Best Answer3 Votes

BeginUpdate and EndUpdate are not used to announce or complete the process of adding items. Moreover, both commands are affecting the behavior of the corresponding control.

Usually, a ListBox, ListView or Memo is updated and repainted after each item that we add. Especially when adding a great amount of new entries, this can take a long time (the redrawing takes much more time than the adding).

Because of that, there are the commands BeginUpdate and EndUpdate. BeginUpdate tells the control that it should finish redrawing itself. The next redrawing the not take place until EndUpdate is call. In the time between, you can process the items of the ListBox, ListView or Memo without that this time-consuming repainting is done. By the way, this not only applies to adding items, it is also appropriate when deleting, moving or editing many items at once.
2016-01-12 at 09:40

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.