Alan Colburn wrote: > I wasn't really sure what to put in the subject line ... I'm trying to write > a class which would let me mimic basic outlining features. As you know, an > outline--the kind you used to use in school--has headings, sub-headings, and > sometimes even third or fourth level sub-headings (sub-sub-headings and > sub-sub-sub-headings). A basic OutlineEntry class, I would think, would have > fields representing the text in an outline entry + fields representing the > text's position within an outline hierarchy: > > I. Heading One > --a. Sub-Heading One > ----1. A second level subheading > ----2. Another second level subheading > > My question is what data structure (and/or associated components) should I > use to model an outline, given that users have to be able to insert new > entries, delete entries, move entries up/down/in/out, etc. while updating > all the positions for the rest of the OutlineEntry objects? It seems like > there will be a lot of sorting going on. It also seems like there's probably > some kind of ClientDataSet or XML "stuff" out there with build in methods > that ought to be well suited for what I'm thinking about ... but I really > have no idea where to start!
What you've described is a basic, run-of-the-mill tree. Tree nodes have data (the text label) and children (the subheadings). Since you'll probably have multiple top-level headings, you might choose to have a "hidden" node to be the parent of all the top-level headings, or you could have a "forest" -- multiple distinct trees. Check Wikipedia, or _any_ data-structure reference, for more about trees. Storing trees in relational databases typically turns the "child" relation around to become a "parent" relation -- each child node has a single reference to its parent, instead of each parent having a _list_ of children. Tree nodes don't generally keep track of where they are in relation to their siblings, partly because of the hassle of keeping that information updated during operations to otherwise unrelated areas of the tree. You're welcome to keep track of the node index within the node, though. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

