Delphi非可视化TTree实现

发布于 2024-08-13 13:05:17 字数 68 浏览 4 评论 0原文

我正在寻找一种非可视持久树(TStringTree)实现。如果有人知道它的任何良好实施,请告诉我。

谢谢。

I'm looking for a non visual persistent tree (TStringTree) implementation. If someone known any good implentation of it, please let me know.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

静赏你的温柔 2024-08-20 13:05:17

您将在 DI 容器< 中找到灵活的非可视化树结构/a> 库(商业)。然而,正如其他人上面所指出的,开发自己的功能确实非常容易,只需添加您需要的功能即可。

您只需使用两个基础对象即可:TNode 和TNodeList(例如TObjectList 后代)。至少,TNode 只需要三个成员:字符串数据、对其父节点的引用(如果该节点是根节点,则为 nil)以及 TNodeList(它是其子节点的列表)。剩下的是各种伴随方法的(有点乏味)实现,例如 Add()、Delete()、IndexOf()、MoveTo()、GetFirstChild()、GetNext() 等。基本树应该小于一棵-夜夜。

You'll find a flexible, non-visual tree structure in the DI Containers library (commercial). However, as others have noted above, it's really quite easy to roll your own, adding only the functionality that you need.

You can do with just two base objects: TNode and a TNodeList (e.g. a TObjectList descendant). At minimum, TNode needs just three members: your string data, a reference to its parent node (nil if the node is root), and a TNodeList, which is a list of its child nodes. What remains is the (somewhat tedious) implementation of the various attendant methods such as Add(), Delete(), IndexOf(), MoveTo(), GetFirstChild(), GetNext() etc. The basic tree should be less than a one-nighter.

离线来电— 2024-08-20 13:05:17

当然,还有时髦的 DECAL(以前的 Rosetta),尝试使用接口和变体创建一种 STL。

http://sourceforge.net/projects/decal/

对于人们来说,灵活性比速度更重要。基本树结构是红黑iirc。

And of course there is still the funky DECAL (previously Rosetta), an attempt at creating a kind of STL using interfaces and variants.

http://sourceforge.net/projects/decal/

More for the people that flexibility over speed though. The base tree structure is Red-Black iirc.

北城挽邺 2024-08-20 13:05:17

什么样的树? B树?展开树?红黑树?这些都是常见的树算法类型。

您可能想看看 Julian Bucknall 的书,Tomes of Delphi:数据结构和算法。它具有各种树的实现以及完整的 Delphi 源代码;您可以轻松地调整其中任何一个以使用字符串。

What kind of tree? B-tree? Splay tree? Red-black tree? These are all common types of tree algorithms.

You might want to look at Julian Bucknall's book, Tomes of Delphi: Data Structures and Algorithms. It has all sorts of tree implementations with full Delphi source; you could easily adapt any of them to work with strings.

桃扇骨 2024-08-20 13:05:17

为什么不简单地使用 XML DOM 文档呢?

对于真正微不足道的字符串树来说,它可能有点过分了,但用于此目的不会太繁重,并且具有能够容纳字符串树的几乎任何扩展的好处(用于将每个字符串存储在树 - 作为属性等)如果需要的话。

根据我的经验,通常一开始的微不足道的需求很快就会超出最初或预期的需求。 :)

如果您担心基于 COM 的 XML 实现及其周围的 VCL 包装器的“开销”,您可以查看 TNativeXML

Why not simply use an XML DOM document?

It may be overkill for a truly trivial string-tree, but would not be too burdensome to use for that purpose and has the benefit of being capable of accommodating just about any extension to a string-tree (for storing additional data with each string in the tree - as attributes etc) should the need arise.

In my experience often what starts out as a trivial need can quickly grow beyond the initial or anticipated requirement. :)

If you are concerned about the "overhead" of the COM based XML implementation and the VCL wrapper around it, you might look into TNativeXML

万劫不复 2024-08-20 13:05:17

您可以只使用 tStringList 并添加其他 tStringLists 对象...很粗糙,但如果您的数据只能表示为字符串数据,则它可以工作。

Child := tStringlist.create;
ParentList.AddObject('Child',Child);

当然,更好的解决方案是创建您自己的对象,其中包含对象的对象列表。

You could just use a tStringList and add objects which are other tStringLists... crude, but it works if your data can be represented as only string data.

Child := tStringlist.create;
ParentList.AddObject('Child',Child);

Of course a better solution would be to create your own objects which contain a tobjectlist of objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文