Speed up the display of Delphi list components
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:
Call BeginUpdate before making the changes to the items. When all changes are complete, call EndUpdate to show the changes on screen. BeginUpdate and EndUpdate prevent excessive redraws and speed up processing time when items are added, deleted, or inserted.
Here's a simple source code example for using this technique with a ListBox:
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):
» without the BeginUpdate/EndUpdate lines: 4.3 seconds...
» with BeginUpdate/EndUpdate: 0.1 seconds, that's 43 times faster!
Here's a source code example for using this technique with a Memo:
Memo1.Lines.BeginUpdate; for i := 1 to 5000 do Memo1.Lines.Add('abcd'); Memo1.Lines.EndUpdate;
» without BeginUpdate/EndUpdate: 25 seconds...
» with BeginUpdate/EndUpdate: 0.6 seconds!
转载于:https://www.cnblogs.com/yunhaisoft/archive/2009/05/07/1452032.html
- 点赞
- 收藏
- 分享
- 文章举报
- 用Delphi写ActiveX的经验
- Delphi6利用WebService 编写 SendEMail程序
- delphi 中分隔符分隔的字符串
- Delphi快速从文件流读取数据存入本地txt
- Delphi Opendialog用法
- Delphi选择指定路径作为操作路径
- [转]Delphi 12种大小写转换的方法
- 如何给ActiveX数字签名(Step by Step, Delphi)
- Delphi还是那个Delphi,变化了的只是世界
- 再执牛耳,Delphi的安卓开发,效率与性能兼而有之,比之鱼与熊掌
- Delphi的资料和教程,多多的
- delphi中TreeView使用常见问题
- 用delphi写下载程序
- delphi技巧--分离汉字和英文字母
- delphi中var关键字
- Delphi和C++ Builder中的Hibernate开发(一)
- Delphi和C++ Builder中的Hibernate开发(六)
- 关于C#下写的Web Service 服务在Delphi下调用时的问题
- 简单工厂之Delphi实现
- Delphi 对对碰外挂 记录