Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TListview.items.clear long execution time

Posted on 2003-11-16
9
265 Views
Last Modified: 2010-04-05
hi,

i am coding a simple app which contains a listview and records is inserted & deleted time by time.
Everytime records being refreshed, i call items.clear. i noticed there is quite a long execution time for items.clear. it's around 3 to 5 sec. During that time, i cannot move anything even the cursor, could anyone advise how to minimise the impact.

i am using D7 with win2000,clients machine is P4 with 256 Mb
0
Comment
Question by:lamtl354
9 Comments
 
LVL 5

Expert Comment

by:Hypoviax
ID: 9761160
If you have a lot of items and are calling items.clear regualrly this may take significant cpu time and thus result in the lag. To fix this problem try a linear deletion of the items:

For X:=0 to listview1.items.count-1 do
         begin
          listview1.items.item[x].delete
         end;

Hope this solves your problem

Hypoviax
0
 

Expert Comment

by:13_th
ID: 9761608
variant 1
// unhooking the renovation for time peelings - can enlarge speed

 ListView1.Items.BeginUpdate;
 ListView1.Items.clear;
 ListView1.Items.EndUpdate;

variant 2
//partial removing
 ListView1.Items.BeginUpdate;
For i:=0 to listview1.items.count-1 do
         begin
          listview1.items.item[0].delete;
          Application.ProcessMessages; //to did not hang
         end;
 ListView1.Items.EndUpdate;


0
 
LVL 14

Accepted Solution

by:
DragonSlayer earned 50 total points
ID: 9761616
or, alternatively:

ListView1.Items.BeginUpdate;
try
  ListView1.Items.Clear;
finally
  ListView1.Items.EndUpdate;
end;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Expert Comment

by:13_th
ID: 9761656
>try-finaly-end
IMHO, spare!

0
 

Expert Comment

by:13_th
ID: 9761661
>try-finaly-end
no need
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9761731
my friend, if you don't use the try-finally, and if something goes wrong while clearing the ListView (e.g. you added Objects to your ListView and something goes wrong while freeing them, etc), you will never be able to see refreshes/updates to the listview till you restart your application... better be safe than sorry.  :-)
0
 

Expert Comment

by:13_th
ID: 9761754
I agree . but when calling clear this unlikely.À at accompaniment in list or items[...].delete -  i agree :)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9761763
actually, I didn't notice that we posted the Begin/End-Update thingy only 1 minute (or seconds apart!)... ehhehe... lamtl354, if it works, give the points to 13_th, not me, ok? :-)
0
 
LVL 1

Expert Comment

by:hacibumbala
ID: 9762187
Adding large number of items to a list view cripples, even crashes your application. I would recommend using Virtual ListView (normal ListView with OwnerData = True) instead. See "Virtual ListView" example under Demos folder of Delphi (i.e. C:\Program Files\Borland\Delphi7\Demos\Virtual Listview). Or, you may use a third-party component:

http://www.delphi-gems.com/VirtualTreeview/VT.php
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
When I am typing into a TEdit last word repeats 7 145
Delphi: Connect to running MS Outlook 4 117
firemonkey keyboard covers the controls 1 37
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question