预步骤第一步,定义数据结构
type
PMyRec = ^TMyRec;
TMyRec = record
Caption: WideString;
end;
预步骤第二步,规定取得节点数据时候的大小
procedure TMainForm.FormCreate(Sender: TObject);
begin
VST.NodeDataSize := SizeOf(TMyRec); // 如果没用到数据,貌似屏蔽也没关系
// VST.RootNodeCount := 20; // 可以尝试指定节点数据
end;

第一步,初始化节点的内容(赋值):
procedure TMainForm.VSTInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var
Data: PMyRec;
begin
with Sender do
begin
Data := GetNodeData(Node); // 只是取得当前节点的指针而已,其内容仍需程序员处理
// 建立每个节点的数据,注意每个节点只触发一次。
// 为数据赋值,一次赋值,永远拥有。而不是每次重复赋值。异步显示刚增加的数据
Data.Caption := Format('Level %d, Index %d', [GetNodeLevel(Node), Node.Index]);
end;
end;

第二步,定义某个GetText函数,用来自动随时取得某个节点的数据:
procedure TMainForm.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var
Data: PMyRec;
begin
// A handler for the OnGetText event is always needed as it provides the tree with the string data to display.
// Note that we are always using WideString.
Data := Sender.GetNodeData(Node);
if Assigned(Data) then Text := Data.Caption; // 这句非必要,是在写窗口的Caption,但很好的演示了取到数据以后可以做很多事情
end;

第三步,增加根节点,或者子节点。或者清除所有节点:VST.Clear;
procedure TMainForm.AddButtonClick(Sender: TObject);
var
Start: Cardinal;
begin
with VST do
begin
Start := GetTickCount; // 计算时间
case (Sender as TButton).Tag of
0: // add to root
begin
RootNodeCount := 10; // 就这一句就足够增加节点了
end;
1: // add as child
if Assigned(FocusedNode) then
begin
ChildCount[FocusedNode] := ChildCount[FocusedNode] + 2; // ChildCount 和 FocusedNode 都是自带属性
Expanded[FocusedNode] := True; // 自带展开方法
InvalidateToBottom(FocusedNode); // 自带全部刷新
end;
end;
// 速度快啊,10万个节点32ms. 100万个节点200ms左右,1000万个节点40秒(内存不够,硬盘狂闪)
// Label1.Caption := Format('Last operation duration: %d ms', [GetTickCount - Start]);
end;
end;

最后,释放节点:
procedure TMainForm.VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
Data: PMyRec;
begin
Data := Sender.GetNodeData(Node);
// Explicitely free the string, the VCL cannot know that there is one but needs to free
// it nonetheless. For more fields in such a record which must be freed use Finalize(Data^) instead touching
// every member individually.
Finalize(Data^);
end;

TVirtualNode = packed record
Index, // index of node with regard to its parent
ChildCount: Cardinal; // number of child nodes
NodeHeight: Word; // height in pixels
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
Align: Byte; // line/button alignment
CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
CheckType: TCheckType; // indicates which check type shall be used for this node
Dummy: Byte; // dummy value to fill DWORD boundary
TotalCount, // sum of this node, all of its child nodes and their child nodes etc.
TotalHeight: Cardinal; // height in pixels this node covers on screen including the height of all of its
// children
// Note: Some copy routines require that all pointers (as well as the data area) in a node are
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
// data) then put them before field Parent.
Parent, // reference to the node's parent (for the root this contains the treeview)
PrevSibling, // link to the node's previous sibling or nil if it is the first node
NextSibling, // link to the node's next sibling or nil if it is the last node
FirstChild, // link to the node's first child...
LastChild: PVirtualNode; // link to the node's last child...
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
end;

TVirtualStringTree的Minimal例子学习的更多相关文章

  1. 数百个 HTML5 例子学习 HT 图形组件 – 3D建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  2. 数百个 HTML5 例子学习 HT 图形组件 – 3D 建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  3. 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇

    <数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...

  4. 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇

    HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...

  5. HTML5 例子学习 HT 图形组件

    HTML5 例子学习 HT 图形组件 HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心 ...

  6. pytorch例子学习-DATA LOADING AND PROCESSING TUTORIAL

    参考:https://pytorch.org/tutorials/beginner/data_loading_tutorial.html DATA LOADING AND PROCESSING TUT ...

  7. 通过例子学习C++(二)最小公倍数

    本文是通过例子学习C++的第二篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其最小公倍数. 解答方法一:两个数的最小公倍数,是这两个数中的大数,或者是这2个数的倍数中的最小 ...

  8. 通过例子学习C++(三)最大公约数,并知其然

    本文是通过例子学习C++的第三篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其大公约数. 解答方法一:两个数的最大公约数,是这两个数中的小数,或者是这2个数的公约数中的最大 ...

  9. nodeJs 5.0.0 安装配置与nodeJs入门例子学习

    新手学习笔记,高手请自动略过 安装可以先看这篇:http://blog.csdn.net/bushizhuanjia/article/details/7915017 1.首先到官网去下载exe,或者m ...

随机推荐

  1. POJ 3268 Silver Cow Party (Dijkstra + 优先队列)

    题意:由n个牧场,编号1到n.每个牧场有一头牛.现在在牧场x举办party,每头牛都去参加,然后再回到自己的牧场.牧场之间会有一些单向的路.每头牛都会让自己往返的路程最短.问所有牛当中最长的往返路程是 ...

  2. [HAOI2011]Problem b&&[POI2007]Zap

    题目大意: $q(q\leq50000)$组询问,对于给定的$a,b,c,d(a,b,c,d\leq50000)$,求$\displaystyle\sum_{i=a}^b\sum_{j=c}^d[\g ...

  3. Laravel 时间处理

    $info['date'] = $item->created_at->diffForHumans();//友好时间显示 $info['date'] = $item->created_ ...

  4. 获取Android系统默认给每个app分配的内存上限

    ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); int ...

  5. 【好】Paxos以及分布式一致性的学习

    Paxos,一言以蔽之,我们需要一种提交协议来确保分布式系统中的全局操作即使是在发生故障的情况下也能保证正确性. 跟拜占庭将军问题是不同的问题,虽然拜占庭也是Lamport提出的.拜占庭里面有叛徒,有 ...

  6. 如何选择Haproxy和Nginx

    对于做软负载,我们都知道主流的方案有LVS.Haproxy.Nginx!那么对于Haproxy和Nginx,我们如何选择呢?回答这个问题之前,我根据个人使用经验来讲下它们的特点! Haproxy特点 ...

  7. Batch update returned unexpected row count from update [0];

    Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested ...

  8. hibernate 过滤

    1.可以使用@Where的过滤,不过这种过滤式全局的,支持延迟加载. 2.可以使用@Filters,这种过滤不支持延迟加载. @Entity@Table(name = "qc315_tous ...

  9. 非常酷的word技巧---删除行前的空格

    今天整理一篇文章的时间遇见一个问题,非常多行前的空格严重影响美观.搞计算机的就是爱折腾.于是做了各种尝试完美解决,以下把方法发布例如以下,事实上非常easy哦! 问题例如以下情况所看到的: 解决的方法 ...

  10. iOS之手势滑动返回功能

    iOS中如果不自定义UINavigationBar,通过手势向右滑是可以实现返回的,这时左边的标题文字提示的是上一个ViewController的标题,如果需要把文字改为简约风格,例如弄过箭头返回啥的 ...