从 ListView 切换到 VirtualStringTree
我正在尝试使用 VirtualStringTree 而不是 Listview 来构建我的项目,因为速度差异巨大。问题是,即使在浏览了演示之后,我还是无法确切地弄清楚如何将它用作 ListView。就像添加、删除以及基本上使用 ListView 项目一样简单,但是当我查看 VT 时,它几乎变得太复杂了。
我所寻找的只是一个看起来像ListView的VT,带有子项等。
以下是一些使用ListView的例程,我想将它们与VT一起使用(这只是一个伪示例:
procedure Add;
begin
with ListView.Items.Add do
Begin
Caption := EditCaption.Text;
SubItems.Add(EditSubItem.Text):
End;
end;
Procedure ReadItem(I : Integer);
begin
ShowMessage(ListView.Items[I].Caption);
ShowMessage(ListView.Items[I].SubItems[0]);
end;
当然,还有删除功能,但因为那就像 1 行,我没有打扰:P
有人可以将上面的示例翻译为使用 ListView 样式 VT
谢谢!
I am trying to build my projects with a VirtualStringTree rather than a Listview, because of the vast speed difference. The thing is, even after looking thru the demo's, I just can't figure out exactly how I would use it as a ListView. Like, adding, deleting, and basically just working with ListView items is so easy, but when I look at the VT, it gets almost too complicated.
All I am looking for, is a VT that looks like a ListView, with subitems etc.
Here are some routines using the ListView, that I would like to use with VT (This is just a pseudo example:
procedure Add;
begin
with ListView.Items.Add do
Begin
Caption := EditCaption.Text;
SubItems.Add(EditSubItem.Text):
End;
end;
Procedure ReadItem(I : Integer);
begin
ShowMessage(ListView.Items[I].Caption);
ShowMessage(ListView.Items[I].SubItems[0]);
end;
Of course, also the Delete function, but since thats like 1 line, I didnt bother :P
Could anyone maybe translate the above examples into using a ListView style VT?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为什么不在虚拟模式下使用列表视图?这看起来、感觉起来都不错,而且性能也很棒。
Delphi TListView 控件是 Windows 列表视图组件的包装器。在其默认操作模式下,列表数据的副本将从您的应用程序传输到 Windows 控件,这很慢。
在 Windows 术语中,替代方法称为虚拟列表视图。您的应用程序不会将数据传递给 Windows 控件。相反,当控件需要显示数据时,它只会向您的应用程序询问所需的数据。
Delphi TListView 控件通过使用 OwnerData 属性公开虚拟列表视图。您必须稍微重写列表视图代码,但这并不太难。
我还提供了另一个问题的链接 这里涵盖了类似的内容。相当奇怪的是,该问题的接受答案谈到了列表框,尽管问题是关于列表视图控件的。
Why don't you use a list view in virtual mode? That will look and feel right and perform great.
The Delphi TListView control is a wrapper around the Windows list view component. In its default mode of operation copies of the list data are transferred from your app to the Windows control and this is slow.
The alternative to this is known as a virtual list view in Windows terminology. Your app doesn't pass the data to the Windows control. Instead, when the control needs to display data it asks your app for just the data that is needed.
The Delphi TListView control exposes virtual list views by use of the OwnerData property. You'll have to re-write your list view code somewhat but it's not too hard.
I also offer a link to another question here that covered similar ground. Rather oddly, the accepted answer for that question talked about list boxes even though the question was about list view controls.
使用 VirtualStringTree 它比简单的 TListView 稍微复杂一些,但是这里有一个非常简单的教程,我不久前创建了有关如何使用 VirtualStringTree http://www.youtube.com/watch?v=o6FpUJhEeoY 我希望它有帮助,干杯!
with VirtualStringTree it's a bit more complex than the simple TListView, however here's a very simple tutorial that I've created a little while back on how to use VirtualStringTree http://www.youtube.com/watch?v=o6FpUJhEeoY I hope it helps, cheers!
只需使用普通的 TListView,但在虚拟模式下使用它。
这非常简单:
OwnerData
属性设置为true
OnData
事件处理程序。显示 3 行简单列表的示例实现:
仅此而已!
需要记住的一些事情:
Just use your normal TListView, but use it in virtual mode.
It's really simple:
OwnerData
property totrue
OnData
event handler.Sample implementation that shows a simple list of 3 rows:
That's all!
Some things to keep in mind:
基本上这就是您需要做的,但是 VirtualStringTree 有/需要很多其他东西一起工作才能完全理解它。一旦您“掌握”了 VST,它就会变得简单而强大。以下网页将为您提供帮助:http://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus
,下面我将添加我使用更多代码来显示简单的 VST 日志。我将所有代码保留在数据模块中,只需使用程序 Log 来显示信息并将您的 FormMain.vstLog 更改为您的
......
Basically that is what you need to do, but the VirtualStringTree has/needs alot of other things working together to fully understand it. And once you "get it" the VST is easy and powerful. The following webpage will help you: http://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus
and below I will add more code I use for a simple VST Log display. I keep all the code in datamodule, just use the procedure Log to display information and change your FormMain.vstLog to yours...
...
获取 VT Contributions 包并查看 的一些后代虚拟字符串树。那些都在里面。我没有在项目中使用过它们,但它们似乎使虚拟字符串树更易于使用。
这里是我的入门入门:
在使用虚拟字符串树相当多之后,我发现充分利用它的唯一方法是实现 init 节点/子函数并设置根节点计数,与使用ownerdraw := true 的列表视图非常相似。
使用 VirtualStringTree 做事情非常容易,您只需要实现获取文本函数和节点大小函数(将其设置为等于您想要用作树背后的数据的任何记录的大小)
我发现这几乎总是更容易做到
<代码>
TVirtualTreeNodeRecordData = 记录
数据:TVirtualTreeNodeData;
结尾
并在 init 函数上创建数据对象。它为您创建指针,但您需要释放对象(再次使用另一个删除节点回调)。
Get the VT Contributions pack and check out some of the descendants of virtual string tree. That are in there. I haven't used them in projects, but they seem to make Virtual String Tree easier to use.
Here's my getting started primer nonetheless:
I've found after using Virtual String Tree quite a bit that the only way you can make the most of it is by implementing the init node/child functions and setting the root node count, much the same as you would a list view with ownerdraw := true.
It's pretty easy to do stuff with VirtualStringTree, you just need to implement the get text function and the node size functions (set it equal to the size of whatever record you'd like to use as the data behind your tree)
I've found it's almost always easier to do
TVirtualTreeNodeRecordData = record
Data : TVirtualTreeNodeData;
end
and create the data object on the init functions. It creates the pointers for you, but you need to free the objects (again, use another delete node callback).