Board index » delphi » Fast way to clear a TListItems?

Fast way to clear a TListItems?

On Wed, 01 Jul 1998 16:58:08 GMT, gor...@atlanta.com (Guy Gordon)
wrote:

Quote
>How can I make this faster?

>  RecordListView.Items.BeginUpdate;
>  RecordListView.Items.Clear;           //Takes Long!!
>  RecordListView.Items.EndUpdate;
>  RecordListView.Refresh;

>With several thousand Items, this takes maybe 10 seconds on a 300MHz
>Pentium.  Any faster way to do it?

Two questions:

(1) What happens when you turn sorting off?
(2) Of what possible use might several thousand items in a TListView
be? (There must be a better approach.)

 

Re:Fast way to clear a TListItems?


In article <359adae2.21402...@news.mia.bellsouth.net>,

Quote
  Mauri...@bellsouth.net wrote:

> On Wed, 01 Jul 1998 16:58:08 GMT, gor...@atlanta.com (Guy Gordon)
> wrote:

> >How can I make this faster?

> >  RecordListView.Items.BeginUpdate;

Guy,
try to place here following:
     RecordListView.ItemFocused := RecordListView.Items[0];

I found out the speed of Clear depends on which item is focused,
it was slowest for the last item.

HTH,
         Zdenek

P.S. Sorry, I couldn't answer directly to your question,
     because it didn't appear on Dejanews.

Quote
> >  RecordListView.Items.Clear;           //Takes Long!!
> >  RecordListView.Items.EndUpdate;
> >  RecordListView.Refresh;

> >With several thousand Items, this takes maybe 10 seconds on a 300MHz
> >Pentium.  Any faster way to do it?

> Two questions:

> (1) What happens when you turn sorting off?
> (2) Of what possible use might several thousand items in a TListView
> be? (There must be a better approach.)

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:Fast way to clear a TListItems?


On Thu, 02 Jul 1998 06:50:05 GMT, gor...@atlanta.com (Guy Gordon)
wrote:

Quote
>>Two questions:

>>(1) What happens when you turn sorting off?

>(1)  No difference.  
>I can understand if it takes a long time to add 3000 item, or even to
>sort them.  But why take so long to clear the list?

Drat. I thought the list might resort itself whenever an item is
deleted, but I suppose it doesn't.

If I were in your shoes, I'd try some of these ideas:

1. Perhaps the list might deallocate memory the same way it allocates
it. I'd temporarily change ListView.AllocBy to ListView.Items.Count,
see if that helped.

2. Perhaps the icons have something to do with it (unlikely, I think).
I'd temporarily set ListView.SmallIMages and ListView.LargeImages to
nil.

3. Perhaps ListView.Clear is just kind of dumb. I'd try to delete the
items one by one to see which method was faster.

4. ?

How many subitems (text) does each item have?

Re:Fast way to clear a TListItems?


Quote
><HTML><PRE>How can I make this faster?

>  RecordListView.Items.BeginUpdate;
>  RecordListView.Items.Clear;           //Takes Long!!
>  RecordListView.Items.EndUpdate;
>  RecordListView.Refresh;

>With several thousand Items, this takes maybe 10 seconds on a 300MHz
>Pentium.  Any faster way to do it?

>Thanks

Haven't tried it but...

Create the ListView at runtime then

begin
if ListView.Items.Count  <  500  then
 Listview.Items.Clea  else
  try
      LockWindowUpdate(Form1);
      ListView.Free;  
      ListView := TListView.Create ......
      //setup...
   finally
      LockWindowUpdate(0);
   end;
end;

Chris
c8...@aol.com

Other Threads