Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Optimization of work with standard TTreeView/TListView components Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
17-Sep-02
Category
VCL-General
Language
Delphi 2.x
Views
18
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Mike Shkolnik

Have a bad performance with standard TTreeView/TListView? Read this tip and 
implement the hints...

Answer:

If you uses the TTreeView and/or TListView from Win32 page of default component 
palette, then you must know that if you have the large amount nodes, you have a 
very bad performance...

Of course, at same moment you'll try to find a some other third-party component 
that allow to work with your very large data but I want to give you the few hints 
which allows to increase a performance without any third-party components. Only 
using of optimized code.

Tip1:

if you need add a lot of nodes in same time (for example, after button click to 
load the 10000 nodes in tree from some source) then you must call:

1   yourTreeView.Items.BeginUpdate;
2   
3   yourTreeView.Items.EndUpdate;


This constuction will disable a repainting when you append the nodes - it's save a 
lot of time!

Tip2:

if you uses the some navigation by nodes, you must use the GetFirst and GetNext 
methods instead Items[i] using!

For example:

4   var
5     node: TTreeNode;
6   begin
7     node := yourTreeView.Items.GetFirstNode;
8     repeat
9       node := Result.GetNext;
10    until node = nil;
11  end;


It's save a lot of time too! The GetFirstNode/GetNext is faster than standard

12  for i := 0 to yourTreeView.Items.Count - 1 do
13  begin
14    node := yourTreeView.Items[i];
15  end;


Tip3:

Also, when adding lots of items, you could do 
16  
17  MyObj.AllocBy := 10000;


This will cause fewer allocations as it allocates more items each time.

For example, in own warehouse system I have a treeview with 5000 nodes which I load 
from Oracle resultset. After applying of these tips, the time of execution of 
procedure with append was decreased from 4-5 minutes to 15-20
seconds! Trust me :-)

I don't sure but I think that it's a bad work of Borland when team developed the 
envelope for Win's treeview/listview. But maybe I'm wrong.

PS: of course, if you have a very-very large data with few billions of nodes or 
after applying of tips above all the same you have a bad performance, you must use 
the virtual mode of control or really select the other third-party
control. But I suggest to change the your interface logic - to navigate thru few billions of nodes in same time is very hard task for user! Not only for you :-)

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC