< listview.Clear>之间的区别究竟是什么和< listview> .items.clear在delphi 7中? [英] What exactly is the difference between <listview.Clear> and <listview>.items.clear in delphi 7?

查看:373
本文介绍了< listview.Clear>之间的区别究竟是什么和< listview> .items.clear在delphi 7中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么有两种不同的清除列表的方法。一个是通过调用 listview.clear 而另一个是 listview.items.clear 。实际上,这也扩展到许多其他VCL组件。必须使用哪种方法,为什么?

I would like to know why are there 2 different ways of clearing out a listview. One is by calling listview.clear and other is listview.items.clear. Actually, this extends to many other VCL components too. which method must be used and why?

提前感谢

推荐答案

ListView.Clear 只是围绕 ListView.Items.Clear ListItems.BeginUpdate / ListItems.EndUpdate 。看看来源:

ListView.Clear is just a wrapper around ListView.Items.Clear with ListItems.BeginUpdate/ListItems.EndUpdate. look at the source:

procedure TCustomListView.Clear;
begin
  FListItems.BeginUpdate;
  try
    FListItems.Clear;
  finally
    FListItems.EndUpdate;
  end;
end;

从文档:


BeginUpdate方法暂停屏幕重绘,直到调用EndUpdate
方法。使用BeginUpdate来加快处理速度,避免
闪烁,同时将项目添加到集合中或从集合中删除。

The BeginUpdate method suspends screen repainting until the EndUpdate method is called. Use BeginUpdate to speed processing and avoid flicker while items are added to or deleted from a collection.

更好的做法是使用 BeginUpdate / EndUpdate 以提高速度,避免闪烁。

但是使用的主要原因 ListView.Clear 是因为使用高级VCL方法(由@Arnaud评论)总是一个好主意,实现可能会改变(BTW,方法在D7中引入。

A better practice is to use BeginUpdate/EndUpdate for speed and avoiding flicker.
But the main reason to use ListView.Clear is because using a "high-level VCL methods" (As well commented by @Arnaud) is always a good idea, and the implementation might change (BTW, the method was introduced in D7).

编辑:我已经测试了 TListView 10k 项目(D7 / WinXP):

I have tested the TListView with 10k Items (D7/WinXP):


  • ListView.Items.Clear :〜5500 ms

  • ListView.Clear :〜330 ms

  • ListView.Items.Clear: ~5500 ms
  • ListView.Clear: ~330 ms

结论: ListView.Clear ListView.Items.Clear BeginUpdate / EndUpdate 不被使用!

Conclusion: ListView.Clear is about 16 times faster than ListView.Items.Clear when BeginUpdate/EndUpdate is not used!

这篇关于< listview.Clear>之间的区别究竟是什么和< listview> .items.clear在delphi 7中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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