TWebTreeView questions

I put five items into a TWebTreeView, as Level=0 items. Then I added children to each of them.

When I tried to iterate through all of the items, I did this:

for i := 0 to tv.Items.Count-1

and it stopped early. It seems that while there were 35 or so things in Items, tv.Items.Count was only = 5 because it's only counting the Level=0 items. I believe the VCL TTreeView returns however many nodes are in the Items property.

In this case, I wanted to iterate over all of the Items, so I changed this to read:

tn := tv.Items[0];
while Assigned( tn ) do
begin
  if (tn.Level = 0) then
    . . . do somethign with the Level=0 node
  else
    . . . do something with the child node
  tn := tn.GetNext;
end;

If I have one of these Level=0 nodes, then from what I can tell, I should be able to access the 3rd child node of some node tn0 at Level=0 as:

tn1 := tn0.Item[2];

My question is, how do I refer to the 3rd Level=0 node?

If the tv.Items property only refers to Level=0 nodes, then it would be tv.Items[2], right?

But if Items refers to ALL nodes, then would I use tv.Item[2] instead?

NOTE:

tn0 := tv.Item[2]; -- this actually throws a compiler error saying: identifier not found "Item"

So how would you refer to the Level=0 items using a TTreeNode variable that has the .Item property defined to access child nodes? Is it even possible?

Is there an implied "root node" that can be referenced somehow? tv.TopItem causes a compiler error (it's not defined), but it should return tv.Items[0], which is not the same as a "root node".

I'm looking at both the VCL docs and the WEB Core docs and neither one of them is very clear. The WEB Core docs don't even mention TTreeNode or TTreeNodes, so you can't even tell if there's a .Item[] property or not.

It's quite subtle having both .Item[] and .Items[] properties that are slightly different.

We did improvements to make the interface equal to the VCL TTreeView in this regard.
These improvements will be in the next update.

That's great, but ... I cannot find whether .Item is defined on the treeview itself or only on the TTreenodes. I mean, right now it's not defined. I don't know if the VCL version has it or not, but I can't tell from the docs.

I added my own 'rootnode' via
tn0 := lv.Items.Add('rootnode');

and then added the other top nodes to this rootnode so I can find them via tn0.Item[n].

Is this the only way to do that?

.Item is not defined at TWebTreeView level just like it is not defined at VCL TTreeView level.

In the next update, it will be also possible to add a root node via:

tn0 := tv.Items.AddChild(nil, 'first node');

1 Like