What we did was to do stuff in the "OnExpanding" (from memory) node event
which went away and got info from the object hierarchy, which had all the
encapsulation inheritance and polymorphism stuff in it (I can say them even
if I can't smell them).
As you say, it didn't avoid the hierarchy (that wasn't the intention) but it
did avoid mixing the tree-building logic with the other information logic,
which we decided was a clean separation of roles - and we didn't have to
worry about breaking any of the tree code, including Sort. We didn't need to
create descendant nodes or anything, all we did was give it the ability to
build each successive level based on the helper object it was associated
with in the external hierarchy.
(BTW its Max not Mark)
Max
[Phil Said]
Using helper objects doesn't mean, though, that you need to avoid
inheritance. In your case you could create descendant nodes for no other
reason than to store a helper object (and maybe carry out a few maintenance
operations). You could create a new custom node for each kind of helper
object, or (as you hinted at in the e-mail you sent me privately) use
interfaces to work with a standard set of methods on any kind of object - a
much cleaner solution in my opinion.
The components I have made by descending from TCustomTreeView, TTreeNodes,
and TTreeNode are generic. They have simply adapted the TTreeview to allow
any kind of node(s) to be stored inside it as long as they are descendants
of TTreeNode. In your case, it would be useful for no other reason than to
allow you to store a node that new how to talk to your helper objects. This
may be trivial but infact it allows a significant code-reuse benefit the
next time you have to do a similar treeview on a different form or with
different data because all the code for adding and talking to the helper
objects is encapsulated in your TTreeNode descendant ("encapsulated" is a
good OOD word :-). And you still have the NodeObject property to play with.
Now if only someone was able to answer my first query about the
Items.clearcache call in the CustomSort routine :-(
Phil.
[Mark Said]
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz