Virtual Treeview 5.0.0的安装以及入门

    Virtual Treeview是一个“纯VCL”控件,这意味着它不是基于任何系统控件,而是重新编写的。正如它的名字已经表明,这个控件与其他这类控件相比,使用了一个不同的树管理模式。它不知道它所管理的数据是什么东西(除了它的大小),甚至没有一个节点的标题。一切都获取于通过应用程序的事件(或通过派生覆盖方法)。Virtual Treeview是经过精心设计和彻底的测试。这个控件证明了它的概念以及在许多商业产品和免费软件的项目中都很健康的运行。

    Virtual Treeview是非常快的。增加一百万节点只需要700毫秒。需要很少的内存开销。很适合高速接入,遍历一百万个节点只需要不到0.5秒的时间。支持多选,支持背景图片,支持复选框,支持右键菜单,支持节点排序,支持Unicode,支持拖曳,支持剪贴板,支持多行列标题等等。

官方网站:http://www.soft-gems.net/index.php
SVN地址:http://virtual-treeview.googlecode.com/svn/trunk/
本地下载:http://download.csdn.net/source/3317617

安装方法:以Delphi 7为例,用IDE打开".../Packages/Delphi 7"下的"VirtualTreesR.dpk",将".../Source"和".../Common"路径添加到"Environment Options"下的"Library"里,进行"Compile"。再打开"VirtualTreesD.dpk",进行"Compile",接着进行"Install",成功提示如下图:

然后保存退出。

学习Virtual Treeview要通过官方的英文文档和自带的Demos,首先可以看".../Demos/Minimal"的例子,这是最简单的使用示范。下面开始自己测试一下:
1.新建一个Delphi应用程序,拖动"Virtual Controls"面板下的"VirtualStringTree"到窗体上;
2.单元文件所有代码如下:

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{------------------------------------------------------------------------------- 
 在Delphi 7下Virtual Treeview的简单使用    http://blog.csdn.net/akof1314 
-------------------------------------------------------------------------------} 
unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, VirtualTrees, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    vrtlstrngtrVST: TVirtualStringTree; 
    btnAddRoot: TButton; 
    btnAddChildren: TButton; 
    btnClear: TButton; 
    edtNumber: TEdit; 
    grp1: TGroupBox; 
    procedure FormCreate(Sender: TObject); 
    procedure btnAddRootClick(Sender: TObject); 
    procedure btnAddChildrenClick(Sender: TObject); 
    procedure btnClearClick(Sender: TObject); 
    procedure vrtlstrngtrVSTInitNode(Sender: TBaseVirtualTree; ParentNode, 
      Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); 
    procedure vrtlstrngtrVSTGetText(Sender: TBaseVirtualTree; 
      Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; 
      var CellText: WideString); 
    procedure vrtlstrngtrVSTFreeNode(Sender: TBaseVirtualTree; 
      Node: PVirtualNode); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
{------------------------------------------------------------------------------- 
 Description: 定义一个记录类型,根据所需添加内容 
-------------------------------------------------------------------------------} 
type 
  PMyRec = ^TMyRec; 
  TMyRec = record            //记录自己的节点结构类型 
    Caption: String
  end
{------------------------------------------------------------------------------- 
 Description: 创建创建函数 
-------------------------------------------------------------------------------} 
procedure TForm1.FormCreate(Sender: TObject); 
begin 
  vrtlstrngtrVST.NodeDataSize := SizeOf(TMyRec);   //设置节点数据空间 
  vrtlstrngtrVST.RootNodeCount := 20;              //设置初始化节点数 
end
{------------------------------------------------------------------------------- 
 Description: 添加节点 
-------------------------------------------------------------------------------} 
procedure TForm1.btnAddRootClick(Sender: TObject); 
var 
  Count: Cardinal; 
begin 
  Count := StrToInt(edtNumber.Text); 
  vrtlstrngtrVST.RootNodeCount := vrtlstrngtrVST.RootNodeCount + Count; 
end
{------------------------------------------------------------------------------- 
 Description: 添加子节点 
-------------------------------------------------------------------------------} 
procedure TForm1.btnAddChildrenClick(Sender: TObject); 
var 
  Count: Cardinal; 
begin 
  with vrtlstrngtrVST do 
  begin 
    if Assigned(FocusedNode) then 
    begin 
      Count := StrToInt(edtNumber.Text); 
      ChildCount[FocusedNode] := ChildCount[FocusedNode] + Count; 
      Expanded[FocusedNode] := True;      //展开节点 
      InvalidateToBottom(FocusedNode);    //刷新此节点以下的区域 
    end
  end
end
{------------------------------------------------------------------------------- 
 Description: 清除所有节点 
-------------------------------------------------------------------------------} 
procedure TForm1.btnClearClick(Sender: TObject); 
begin 
  vrtlstrngtrVST.Clear; 
end
{------------------------------------------------------------------------------- 
 Description: 每个节点异步触发一次 
-------------------------------------------------------------------------------} 
procedure TForm1.vrtlstrngtrVSTInitNode(Sender: TBaseVirtualTree; 
  ParentNode, Node: PVirtualNode; 
  var InitialStates: TVirtualNodeInitStates); 
var 
  Data: PMyRec; 
begin 
  with Sender do 
  begin 
    Data := GetNodeData(Node); 
    Data.Caption := Format('等级 %d,索引 %d',[GetNodeLevel(Node),Node.Index]); 
  end
end
{------------------------------------------------------------------------------- 
 Description: 树节点显示的字符串数据 
-------------------------------------------------------------------------------} 
procedure TForm1.vrtlstrngtrVSTGetText(Sender: TBaseVirtualTree; 
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; 
  var CellText: WideString); 
var 
  Data: PMyRec; 
begin 
  Data := Sender.GetNodeData(Node); 
  if Assigned(Data) then 
    CellText := Data.Caption; 
end
{------------------------------------------------------------------------------- 
 Description: 释放节点数据 
-------------------------------------------------------------------------------} 
procedure TForm1.vrtlstrngtrVSTFreeNode(Sender: TBaseVirtualTree; 
  Node: PVirtualNode); 
var 
  Data: PMyRec; 
begin 
  Data := Sender.GetNodeData(Node); 
  Finalize(Data^); 
end
 
end

3.运行结果如下图所示:

其他参考资料:
1.Virtual Treeview 官方帮助文档
2.Virtual TreeView使用示例 http://blog.csdn.net/jianfengqu/archive/2008/12/16/3533900.aspx
3.Delphi之Virtual Treeview使用心得 http://hi.baidu.com/lifeprogram/blog/item/e8520fcf711c7f3bf9dc6135.html

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
上传容量有限,含packge和source V5.5.2: (10 Nov 2014) * Various improvements regarding code style * Implemented #471: Added emVisibleDueToExpansion and emSelected to TVTExportMode * Fixed issue #488: XE7 packages should depend on one another and use suffix 21 * Fixed issue #462: Undo r636, make VirtualTreesD require VirtualTreesR again * Fixed issue #489 XE2 compiler switch error V5.5.1: (13 Oct 2014) * Fixed issue #479: The style hooks for the VCL styles are now registered for TVirtualStringTree and TVirtualDrawTree instead of TBaseVirtualTree, which makes it easier to use own style hooks in derived classes. * Partial fix for issue #478: The standard VCL property StyleElemets (public in TControl in RAD Studio XE3 and higher) is now supported and published for TVirtualStringTree and TVirtualDrawTree (XE3 and higher). This means you can define if the font and the backgrounbd color is taken from the VCL style or the control's properties. Leaving out seBorder is not yet working well, more work will be necessary. * Fixed issue #473: Return type of GetUtilityImages should be TCustomImageList * Fix for issue #470: VCL Styles and sorting failure * Added missing inherited to CMMouseEnter() * Fixed issue #468: Redundant code in CreateSystemImageSet() * Fixed issue #482: AutoScale() could cause exception during form load. * Added fix for #466: No parent window if column created in constructor * Fixed issue #446: ScrollIntoView does not work properly after applying patch from issue #339 * Improvements for toAlwaysSelectNode option: Selection of next sibling has been improved in case the currently selected node is being removed. * Added missing begin/end-block in MeasureItemHeight() * Improved fix for issue #438: Now correctly initializing member of property TVTColors.UnfocusedColor * Improved fix for issue #447: DoMeasureItem() was called for Node instead of Child. * Minor improvement in appearance of border lines in HTML export. * Fixed issue #480: Warning when compiling Delphi XE2 packages * Fixed #472: Redundant conditions in TVclStyleScrollBarsHook.WMMouseMove * Fixed #476: Simplify TVTDragImage.WillMove() * Fixed issue #485: unit VirtualTrees does not compile with {$TYPEDADDRESS ON}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值