delphi 中有一个包含多个字段的列表视图.一个线程检查项目并将其添加到列表视图.如果有相同的标题,则在该标题的子项中添加一个整数.当item数小于2000时,性能还可以.当检查和添加项目和项目计数超过2000个时,性能很差.当item数大于20,000时,性能可谓极慢.当项目可能达到 50,000 或 100,000 时,是否有某种方法可以在列表视图中快速读写?
There is a listview with several fields in delphi. A thread checks and adds items to listview. If there is the same caption, an integer will be added in the subitem of this caption. When the item count is less than 2000, the performance is OK. When checking and adding items and items count are more than about 2000, the performance is poor. When items count is larger than 20,000, the performance can be described as extremely slow. Is there some way to fast read and write in listview when the items may reach 50,000 or 100,000 ?
在此先非常感谢您
我们已阅读您的所有回答,感谢大家的帮助.
We have read all your answers and thank all for your help.
推荐答案您只需要在虚拟"模式下使用您的列表.
You just need to use your list in "virtual" mode.
在这段代码中(用你的数据库中的一些数据或 TStringList 等替换):
As in this code (replace with some data from your database or a TStringList or such):
procedure TForm1.ListBox1Data(Control: TWinControl; Index: Integer; var Data: String); begin Data := Format('Item %d',[Index+1]); // set the text to be displayed end;您可以使用 lbVirtualOwnerDraw 样式进一步自定义绘图,并且您必须使用 OnDrawItem 事件处理程序绘制项目.Delphi 文档中有一些示例代码(至少在 Delphi 7 下).;)
You can customize further the drawing by using lbVirtualOwnerDraw style, and you must draw items using an OnDrawItem event handler. There is some sample code in the Delphi documentation (at least under Delphi 7). ;)
在虚拟模式下,您可以瞬间显示 50000 或 100000 个项目.
In Virtual mode, you can display 50000 or 100000 items in an instantaneous way.
为了存储文本,使用旧的 TStringList 将比 TListBox 的 Items 方法更快,因为这个 Items[] 属性必须与 Windows 通信,每个项目的慢"GDI 消息,而 TStringList 将只需将文本存储在 Delphi 堆中,这通常会快得多.
For storing the text, using a good old TStringList will be faster than the Items method of the TListBox, because this Items[] property will have to communicate with Windows with "slow" GDI messages for each item, whereas a TStringList will just store the text in the Delphi heap, which is usually much faster.
更多推荐
如何在delphi的listview中快速读写?
发布评论