Board index » delphi » Why is TTreeView soooooo..... slow???

Why is TTreeView soooooo..... slow???

If I add around 500 items to a TTreeView and then call

"MyTreeView.Items.Clear "

I will wait quite some time (5-10 seconds) on a Pentium 266.

I can load the same data from a database and insert it in a second or two.

Does anybody have any ideas why clearing the control is so slow?

P.S.  I also created a test app and just added a bunch of junk text  and it
still happened so I know its not that I'm allocating lots of memory for my
nodes.

 

Re:Why is TTreeView soooooo..... slow???


Sorry I don't have an answer for you.  I do however feel your pain.
It's so slow that I redesigned my app to avoid using it.  No big loss,
but it would have been nice to use.

Lance
---------------------------------------------------------------------
"...Bond reflected that good Americans were fine people and that most
of them seemed to come from Texas."
{*word*2} Royale. Chapter VII

Re:Why is TTreeView soooooo..... slow???


Quote
> If I add around 500 items to a TTreeView and then call

> "MyTreeView.Items.Clear "

> I will wait quite some time (5-10 seconds) on a Pentium 266.

> I can load the same data from a database and insert it in a second or two.
> Does anybody have any ideas why clearing the control is so slow?

You have to ask that question to Microsoft. Your code executes

procedure TTreeNodes.Clear;
begin
  if Owner.HandleAllocated then
    TreeView_DeleteAllItems(Handle);
end;

TreeView_DeleteAllItems is a function in the commctrl Unit (one of the API
wrapper units) that does nothing more than send a

SendMessage(hwnd, TVM_DELETEITEM, 0, Longint(TVI_ROOT));

All the time is spend in the common control code itself, Delphi is not to
blame here.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:Why is TTreeView soooooo..... slow???


Quote
Ted Nichols wrote:
> If I add around 500 items to a TTreeView and then call

> "MyTreeView.Items.Clear "

> I will wait quite some time (5-10 seconds) on a Pentium 266.

> I can load the same data from a database and insert it in a second or two.

> Does anybody have any ideas why clearing the control is so slow?

> P.S.  I also created a test app and just added a bunch of junk text  and it
> still happened so I know its not that I'm allocating lots of memory for my
> nodes.

Try using  "LockWindowUpdate"  when you do the clear or add nodes this will
stop the screen redraw untill you unlock it
so it may speed things up for you.

LockWindowUpdate(Form1.Handle);
ListView1.Items.Clear;
LockWindowUpdate(0);

Gavin.

Re:Why is TTreeView soooooo..... slow???


Quote
P.K. Information Systems wrote:
> Try using  "LockWindowUpdate"  when you do the clear or add nodes this will
> stop the screen redraw untill you unlock it
> so it may speed things up for you.

> LockWindowUpdate(Form1.Handle);
> ListView1.Items.Clear;
> LockWindowUpdate(0);

What about BeginUpdate/EndUpdate which is supposed to do the same just
for the treeview? I also noticed that if you have a selected node in
tree before clearing, selection goes through the nodes above that node
while clearing up the tree (try putting some code in OnChange-handler).

---
Henri Suuronen

Re:Why is TTreeView soooooo..... slow???


Ted:

Quote
> If I add around 500 items to a TTreeView and then call

> "MyTreeView.Items.Clear "
> I will wait quite some time (5-10 seconds) on a Pentium 266.

It's broken in the newer MS comctl32.DLL (v 4.72.2106.4) that comes with
Delphi 4 and other software, perhaps including IE4.  The good news is
that bracketing your Clear with BeginUpdate and EndUpdate speeds it up
on the order of 100 times.

This works from either D3 or D4.

Earlier versions of the MS comctl32.dll (eg v 4.7 ) Clear much faster,
and see only abot a 2x speedup when using BeginUpdate - EndUpdate.

Graham

Re:Why is TTreeView soooooo..... slow???


Quote
Ted Nichols wrote:
> If I add around 500 items to a TTreeView and then call
> "MyTreeView.Items.Clear "

> I will wait quite some time (5-10 seconds) on a Pentium 266.
> I can load the same data from a database and insert it in a second or two.
> Does anybody have any ideas why clearing the control is so slow?

Cause of Microsoft's implementation. If you want a sofisticated tree, look at
http://members.tripod.com/~Mayevski/programs/bwpack.html. There is a BWTree there, that is
descended from TWinControl. Its features include
-- additional columns for every item
-- multiple selection
-- customizable drag'n'drop
-- smart line hints
-- inplace editing
-- smart pictures displaying
-- customizable colors and font styles for every single item of the BWTree.

--
Bye!
Eugene Mayevski     E-Mail:  mailto:Bu...@i.am
                             http://i.am/bugsy
                      ICQ#:  9409786

Re:Why is TTreeView soooooo..... slow???


Quote
Suuronen Henri wrote:
> I also noticed that if you have a selected node in
> tree before clearing, selection goes through the nodes above that node
> while clearing up the tree (try putting some code in OnChange-handler).

Hmm. What behavior did you expect? Clearing is a recursive deletion of the items. And when
a focused item is deleted, the focus should move to item's parent. Of cause that takes a
lot of time in the standard TreeView implementation.

Quote

> ---
> Henri Suuronen

--
Bye!
Eugene Mayevski     E-Mail:  mailto:Bu...@i.am
                             http://i.am/bugsy
                      ICQ#:  9409786

Other Threads