如何在运行时向 FireMonkey 的 TreeView 添加节点
我在在线文档或 Delphi XE2 附带的演示中找不到任何示例,用于将节点添加到 FMX.TreeView.TTreeView
运行时控件。那么,如何在运行时添加、删除和遍历 FireMonkey TreeView 的节点呢?
I can't found any sample in the online documentation, or in the demos included with Delphi XE2, for adding nodes to a FMX.TreeView.TTreeView
control at runtime. So, how can I add, remove, and traverse nodes of a FireMonkey TreeView at runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想我们现在都在学习...
但是从我所看到的来看,TTreeView 使用的原则是任何控件都可以成为另一个控件的父控件。
您需要做的就是设置
Parent
属性以使项目显示为子项。因此,您可以做以前不可能做的事情,例如在 TreeView 中放置任何控件。例如,此代码将向 Item2 使用的区域添加一个按钮,并且在 Item2 可见之前该按钮不可见。
I think we are all learning at this point...
But from what I have seen the TTreeView use the principle that any control can parent another control.
All you need to do is set the
Parent
Property to get the item to show up as a child.Because of this you can do things never possible before, such as placing any control in the TreeView. For example this code will add a button to the area used by Item2, and the button won't be visible until the Item2 is visible.
使用 AddObject(FmxObject) 您还可以添加任何对象(按钮等)...
With AddObject(FmxObject) you can add any Object (Button etc.) as well...
我有另一个想法。第一个答案帮助我得到了它。
因此,添加以下代码
现在,当您必须释放该项目以使其不使用不必要的内存时,真正的技巧就出现了。假设您在循环中使用它,就像我在这里所做的那样:
I have another idea. The first answer helped me get it.
So Add the following code
Now the actual trick comes when you have to free the item so that it doesn't use unnecessary memory. So lets say you use it in a loop, like I did here:
您的代码不安全。如果 ADOTable 为空,则永远不会创建 TempItem,并且“空闲”将生成访问冲突。
即使表不为空,您也只能释放最后创建的 TempItem。
Your code isn't secure. If ADOTable is empty, TempItem is never created and the 'free' will generate an access violation.
And even if the table is not empty, you will only free the last TempItem created.