What is the best free 3rd Party Tree-implementation for Delphi?
Asked Answered
C

4

6

I'm in need of a tree-implementation that I can use with Virtual Treeview, that does not consume too much memory, is easy to use, and as fast as VT (that is, when I store my data in the VT itself)

I tried the svTree by Linas - its easy to use, however not quite as fast and memory friendly as I had hoped.

Also, just want to point out that my app will be managing thousands of nodes. :)

What free library do you recommend? And would you be able to construct a minimal demo of how to use it with Virtual Treeview?

Contagion answered 9/5, 2011 at 11:7 Comment(25)
Why do you need this ? I would never leave VT.Fuzz
@daemon_x, Jeff has been struggling with the underlying tree datastructure for VT; He wants a data structure he can use with VT.Reproof
@Cosmin - I still can't understand why another component; as the inspiration for the datastructure ? Anyway if he looks for datastructure I would recommend TVirtualNode itself.Fuzz
@daemon_x, he doesn't want an other component, he wants to use VT, but in order to get the full power of VT he needs to keep the data into a separate data structure outside the VT. Since his data shouldn't reside in VT nodes, TVirtualNode is not a solution.Reproof
You already hold the data somewhere. Use that. No need to duplicate it in yet another structure just to display it to the UI. Where do you see problems?Armful
@Cosmin - so what data structure would you recommend ? If he wants to use it with VT he wants also to display them somehow in the VT or not ? And as you said he needs to keep the data into a separate data structure outside the VT but data are already separated.Fuzz
@lars He doesn't hold the data elsewhere. It's owned by the tree view. He needs a tree.Renaissance
-1; this question doesn't make sense to me. To get the full power of VT use it as usually.Fuzz
@David - so if he wants to keep the tree structure which can be used with VT later on why don't use TVirtualNode or TNodeArray array of that. It's the VT's natural type.Fuzz
@daemon that's just a node. That's easy. The hierarchy is the hard part.Renaissance
@David - yes, it's just a node, but this node has everything for building the hierarchy. It has e.g. Index, Parent, PrevSibling, NextSibling, FirstChild, LastChild what is even more than enough to use it.Fuzz
@daemon, some of us apparently know Jeff's tree problem all too well. I already posted a very simple tree data structure in an other one of Jeff's questions. As for myself, I don't store tree data in a tree-specific data structure: I use the virtual tree to display data from it's natural data structure.Reproof
@daemon Does this wonderful node class come with routines to add new nodes into the tree and update all the parent, child and sibling references?Renaissance
@David - this wonderful structure (actually a record) doesn't do anything, just exists :) The rest is done by VT which is IMO very fast and very optimal so I don't know why to look for something separate. If he really wants a tree structure for adding / deleting and iterating through it, it's IMHO enough to have a record with Index, Parent and Level (for faster iteration through the certain node level) and several functions for manipulation with it.Fuzz
@daemon Parent and Level are fine until you want to modify the structure. Maintaining them becomes non-trivial.Renaissance
@daemon - The reason I want to store my data elsewhere, is to make it easier to process my stuff (i.e threads), which I currently can't do without having to access the Main Thread where my VT is.Contagion
@Daemon, it's far from optimal if you wish to have multiple views of the same data, which Jeff has expressed a desire for before, sometimes by showing the same data in multiple tree controls, and sometimes by showing a single node in multiple categories in the same tree control. In either case, it makes things harder to manage if each node is supposedly the owner of the data associated with it, which is what you get if you try to use the tree control as your primary data structure.Aparejo
Jeff, as I recall, you don't really have tree-like data. You have a list of Skype contacts, and they have various properties that make them fall into various classes. A tree isn't necessarily the data structure to use in that case. And even if a tree is the best, there are different kinds of trees and different implementations of trees that perform better at different operations. What kinds of operations do you need to do with this data the most often? Operations include append, insert, delete, find, filter, traverse in various orders.Aparejo
@Rob - My contacts can be grouped into Categories. I need a way to add categories, add users (to categories), traverse the categories, traverse users in the categories, delete categories and users (from categories) - basically what I can do with VT right now, but without being tied to the tree.Contagion
@Contagion - so then create a class which will do the stuff and which will control VT (add, delete nodes etc.) In your data structure you can store your node pointer, so when you for instance delete a category with all contacts you will know the exact node and you'll be able to delete it in VT.Fuzz
@Contagion - and as Rob pointed, there's no need to store the hierarchy if the VT holds it for you.Fuzz
@daemon - Every question I posted that has to do with VT, Rob always told me to stop using VT to store my data, that I should use a separate data structure, that is not tied to the tree.Contagion
@Contagion - but now you can see why this be useful; just imagine a class with functions like Add, Delete etc. where also all your data will be stored. In this class functions you can manipulate even with VT nodes, because you can save the node pointers (PVirtualNode) to that class. And when e.g. some contact is updated (in your worker thread) then you can update that node in your synchronization method.Fuzz
@daemon - Not exactly sure how I would do that - why not post an example as an Answer? :)Contagion
@Contagion - if Cosmin let me modify his anwser you maybe find what you're looking forFuzz
F
3

Have a look at the rmTreeNonView component in rmControls library.

We've been using a modified version of that tree for years as a data container. It's free, fast, non-visual, comes with source code, and is easy to get started with because duplicates TTreeView's methods and properties almost 100%, plus adds some methods of its own--particularly, a fast hash-based search for tree node paths.

I doubt the company is in business any more (http://www.mills-enterprise.ca), but the rmControls package including source is available on many Delphi download sites.

EDIT:

Here's some code showing how to point to nodes in another tree structure from nodes of a VTV...hope I've included enough code to let you see what's going on. TmwDataTreeNode is a node of a TTreeNonView descendant. Note that when the PopulateVT method has completed, the ContextNode field of each TNodeData points to a node in the source data container tree. Note this approach does not make use of VTV's virtual nature, which might more likely be more appropriate for your situation.

type
      //Virtual tree record stuff
  PNodeData = ^TNodeData;
  TNodeData = record
  public
    NodeSelf: PVirtualNode;         //Ptr to our own VT node...needed?
    ContextNode: TmwDataTreeNode;        //ptr to our corresp node of data tree
    GridRecordIndex: integer;      //Grid.RecordIndex of our corresp Alloc formula.
  end;


procedure T_fmExplAllocOut.PopulateVT;
{ Load data to the DragDrop treeview. }
var
  n: TmwDataTreeNode;        //Pointer to a node of my customized TTreeNonView
begin
  VT.NodeDataSize := SizeOf(TNodeData);
  VT.BeginUpdate;
  vtsChangeFontSize(VT, Self.Font.Size);     //Set Tree Font.Size & DefaultNodeHeight
      //Add DragDrop Tree nodes
  n := AllocController.SnapContext.Tree.Items.GetFirstNode;
  while n <> nil do begin
    AddVTNode(nil, n);              //nil=parent node of top-level VT nodes
    n := n.GetNextSibling;
  end;
  VT.FullExpand;
  VT.EndUpdate;
end;


procedure T_fmExplAllocOut.AddVTNode(VTParentNode: PVirtualNode; n: TmwDataTreeNode);
{ Recursively add n & its children to VT. }
var
  NodeData: PNodeData;
  VTNode: PVirtualNode;
begin
  if (n = nil) or not NodeInIncludeFilter(n) then
    exit;
      //Add this node
  VTNode := VT.AddChild(VTParentNode);
  NodeData := VT.GetNodeData(VTNode);
  VT.ValidateNode(VTNode, False);        //else OnFreeNode won't get called
  with NodeData^ do begin
    NodeSelf :=         VTNode;
    ContextNode :=      n;
    GridRecordIndex := -1;
  end;
      //Add child nodes
  n := n.GetFirstChild;
  while n <> nil do begin
    AddVTNode(VTNode, n);            //Pass our added node as Parent
    n := n.GetNextSibling;
  end;
end;
Flack answered 9/5, 2011 at 18:8 Comment(2)
I will have to look into it - so would you say it is very recommended for use with TVirtualStringtree? :)Contagion
@Contagion - "Recommended" by whom, and in the context of what specific purpose? I recommend it as a tree structured data container suitable for my purposes but cannot know whether it would suit yours. (Generally, you can only answer such questions by looking into the component's features on your own.)Flack
A
3

You don't need controls or libraries for remembering data. You need to come up with a data structure that fits your needs. The last step is using VTV or any other control to display your data structure. Stop thinking about the GUI for a minute and think about how you want to build your data structure. Think about design patterns and old fashioned programming, Link lists, arrays, queues, hashlist/dictionaries, red/black trees etc. Each have there own pro's and con's in the for of speed and memory usage of searching, traversing, adding. There are libraries (like http://www.boyet.com/FixedArticles/EZDSL.html) that have the basic building blocks, but you have to figure out what you want. If you get stuck there I advice you to ask a new question and specify the requirements for your data structure. You might want to read https://sites.google.com/site/igetfreebook/The-Tomes-of-Delphi-Algorithms-and-Data-Structures

If your question is about a GUI control that also stores your data, then I wonder why you don't want to use VTV. Maybe other controls are easier, but from a design point of view they are not better. You are still storing your data in a GUI control.

Armful answered 9/5, 2011 at 20:15 Comment(1)
My question is about how I can avoid storing my data in the GUI control. ;) This question has an image of how my GUI control is supposed to look: #5597088Contagion
A
2

It sounds like you have quite specific needs, so I have a feeling there will not be a complete solution to fit your exact requirements.

My first suggestion would be to use a database. It has all the functionality i (think) you need, plus the added bonuses of being robust and very fast. Obvoiusly you are going to have to write some of your routines to handle the addition/deletion/insertion/editing of data etc. A relational database will be able to store all your relations between your categories, and make easy to change relations between your records (nodes). Take the time to learn how to store heirarchical data, and then relationships between your nodes. A well designed database will provide you with all the specifics for your project. MySQL is free and very simple to use. Small footprint, yet very fast. Take a look at this article to get you thinking about how tree data structures can be stored in a relational way : Relational Tree Data structures.

Having said this, im not so sure thats what you are looking for.

An example of how a database can store your tree:

Sample Tree from a database

If a database is unfeasible, then i would encourage you to write your own class. Only you know how your data is managed and fits together. Therefore you can write the exact functionality your tree needs to be manipulated and peiced together. Start by looking at a TObjectList. Create your class object that stores data for each node. Then you can create a list of these objects to hold all of your nodes. Write methods to mimic what user actions are performed on your tree e.g. Add, update, move etc. This may take some time, but it will really help you learn and will benefit you as an application designer. Ask questions as you go when you get stuck.

Autopilot answered 10/5, 2011 at 0:47 Comment(0)
E
0

Some interesting non-visual trees are listed in the answers to: Delphi non visual TTree implementation

One of those may suit your needs.

Epistle answered 10/5, 2011 at 1:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.