开发者

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

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 t开发者_如何学Co use it with Virtual Treeview?


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.


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;


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:

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

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.


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

One of those may suit your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜