代码之家  ›  专栏  ›  技术社区  ›  LeGEC

TListView性能问题

  •  0
  • LeGEC  · 技术社区  · 14 年前

    TListView 组件来显示相当大的数据列表(比如4000行大),而创建列表的速度非常慢—大约需要2-3秒,这使得UI非常滞后,几乎无法使用。

    我填补了这个空缺 TListView.Items 内部 BeginUpdate/EndUpdate 块,只使用预先分配的字符串-我的意思是:我建立一个要存储的所有字符串的列表(这不需要人类注意到的时间), 然后

    我希望在中显示TListView的内容 vsReport

    代码如下所示:

    MyList.Items.BeginUpdate;
    for i := 0 to MyCount - 1 do
    begin
      ListItem := MyList.Items.Add;
      ListItem.Caption := StrCaptions[i];
      ListItem.SubItems.Add(StrSubItems1[i]);
      ListItem.SubItems.Add(StrSubItems2[i]);
    end;
    MyList.Items.EndUpdate;
    

    4 回复  |  直到 14 年前
        1
  •  8
  •   Ondrej Kelle    14 年前

    您可以在虚拟模式下使用listview。请看virtuallistview.dpr演示。

        2
  •  4
  •   SimaWB    14 年前

    你可以试试 Virtual Treeview 组件。它说“虚拟树视图非常快。添加一百万个节点只需要700毫秒”

        3
  •  4
  •   Andrej KirejeÅ­    14 年前

    使用单独的结构来保存数据。将TListView的OwnerData设置为True。

        4
  •  0
  •   Im0rtality    14 年前

    @4000行我只得到~700毫秒(D2009)次。为了获得更高的响应能力,您可以分离到其他线程,或者将脏的Application.ProcessMessages()添加到循环中。

      MyCount := 4000;
    
      dw := GetTickCount();
      for i := 0 to MyCount - 1 do begin
        StrCaptions.Add('caption'+IntToStr(i));
        StrSubItems1.Add('sub1'+IntToStr(i));
        StrSubItems2.Add('sub2'+IntToStr(i));
      end;
      ShowMessageFmt('%u ms', [GetTickCount() - dw]);
    

    打印内容:

      MyList.Clear;
    
      dw := GetTickCount();
      MyList.Items.BeginUpdate;
      for i := 0 to MyCount - 1 do
      begin
        ListItem := MyList.Items.Add;
        ListItem.Caption := StrCaptions[i];
        ListItem.SubItems.Add(StrSubItems1[i]);
        ListItem.SubItems.Add(StrSubItems2[i]);
      end;
      MyList.Items.EndUpdate;
      ShowMessageFmt('%u ms', [GetTickCount() - dw]);
    

    编辑: 为什么