lamtl354
asked on
TListview.items.clear long execution time
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
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
variant 1
// unhooking the renovation for time peelings - can enlarge speed
ListView1.Items.BeginUpdat e;
ListView1.Items.clear;
ListView1.Items.EndUpdate;
variant 2
//partial removing
ListView1.Items.BeginUpdat e;
For i:=0 to listview1.items.count-1 do
begin
listview1.items.item[0].de lete;
Application.ProcessMessage s; //to did not hang
end;
ListView1.Items.EndUpdate;
// unhooking the renovation for time peelings - can enlarge speed
ListView1.Items.BeginUpdat
ListView1.Items.clear;
ListView1.Items.EndUpdate;
variant 2
//partial removing
ListView1.Items.BeginUpdat
For i:=0 to listview1.items.count-1 do
begin
listview1.items.item[0].de
Application.ProcessMessage
end;
ListView1.Items.EndUpdate;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>try-finaly-end
IMHO, spare!
IMHO, spare!
>try-finaly-end
no need
no need
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. :-)
I agree . but when calling clear this unlikely.À at accompaniment in list or items[...].delete - i agree :)
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? :-)
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\Demo s\Virtual Listview). Or, you may use a third-party component:
http://www.delphi-gems.com/VirtualTreeview/VT.php
http://www.delphi-gems.com/VirtualTreeview/VT.php
For X:=0 to listview1.items.count-1 do
begin
listview1.items.item[x].de
end;
Hope this solves your problem
Hypoviax