0
votes

This sounds really simple but it's like an onion - lots of layers as you peel. I have a hierarchy of my own object classes - a bit like the components on a form really, in that any of them can have children and a parent. At the top there is a root object. Other code manages this hierarchy and it is possible that branches or leaves may be created, deleted or renamed at any time. I wish to have a tree view (of some kind, probably virtual) which provides a view of this hierarchy in such a way that it is possible to have multiple of these tree views, each drawing themselves from the object hierarchy as required.

I already have a solution using Delphi's TTreeView but it relies on iterating through the hierarchy when a 'changed' flag is raised and rebuilding tree view branches that have changed. This is slow (I can have over 1000 objects) and I'd like an algorithm that manages to do a single tree view change for a single object insertion or deletion.

Is this possible?

1

1 Answers

1
votes

Surely you can detect that an object has been inserted or deleted and make the necessary change.

For example, for a deletion, find the node associated with the deleted object and then delete it. For an insertion, find the object associated with the parent, and then insert a new node in the right place.

If there are performance problems with walking the tree to find the node associated with the object, then you could use a dictionary.

For a virtual tree view it's easier because you just get the tree view to reflect the object structure. When a change is made you request an update and it all happens naturally.