如何在delphi中快速阅读和写入listview? [英] How to fast read and write in listview in delphi?

查看:481
本文介绍了如何在delphi中快速阅读和写入listview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在delphi中有几个字段的列表视图。线程检查并添加项目到listview。如果有相同的标题,则会在该标题的子项中添加一个整数。当项目数小于2000时,性能就OK了。当检查和添加物品和物品数量超过约2000时,性能差。当物品数量大于20,000时,性能可以说是非常慢的。当项目可能达到50,000或100,000时,有没有办法在listview中快速阅读和写入?



非常感谢您提前



修改:


解决方案

我们已经阅读了所有的答案,感谢所有的帮助。虚拟模式。


  1. 将TListBox放在您的表单上;

  2. 将Style属性设置为lbVirtual。 >
  3. 将Count属性设置为列表中的项目数。

  4. 然后使用OnData处理程序提供要显示的文本:

As在这段代码中(用数据库中的一些数据或TStringList替换):

  procedure TForm1.ListBox1Data(Control:TWinControl ; Index:Integer; 
var Data:String);
begin
数据:= Format('Item%d',[Index + 1]); //设置要显示的文本
end;

您可以使用lbVirtualOwnerDraw样式进一步绘制图形,并且必须使用OnDrawItem事件处理程序绘制项目。 Delphi文档中有一些示例代码(至少在Delphi 7下)。 ;)



在虚拟模式下,您可以立即显示50000或100000个项目。



文本,使用一个好的旧TStringList将比TListBox的Items方法更快,因为这个Items []属性将必须与Windows通信与每个项目的慢GDI消息,而TStringList将只存储文本Delphi堆,通常要快得多。


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 ?

Thank you very much in advance

Edit:

We have read all your answers and thank all for your help.

解决方案

You just need to use your list in "virtual" mode.

  1. Put a TListBox on your form;
  2. Set the Style property to lbVirtual.
  3. Set the Count property to the number of items of your list.
  4. Then use the OnData handler to provide the text to be displayed on request:

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;

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). ;)

In Virtual mode, you can display 50000 or 100000 items in an instantaneous way.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆