TVirtualStringTree的Minimal例子学习
预步骤第一步,定义数据结构
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例子学习的更多相关文章
- 数百个 HTML5 例子学习 HT 图形组件 – 3D建模篇
http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...
- 数百个 HTML5 例子学习 HT 图形组件 – 3D 建模篇
http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...
- 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇
<数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...
- 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇
HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...
- HTML5 例子学习 HT 图形组件
HTML5 例子学习 HT 图形组件 HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心 ...
- pytorch例子学习-DATA LOADING AND PROCESSING TUTORIAL
参考:https://pytorch.org/tutorials/beginner/data_loading_tutorial.html DATA LOADING AND PROCESSING TUT ...
- 通过例子学习C++(二)最小公倍数
本文是通过例子学习C++的第二篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其最小公倍数. 解答方法一:两个数的最小公倍数,是这两个数中的大数,或者是这2个数的倍数中的最小 ...
- 通过例子学习C++(三)最大公约数,并知其然
本文是通过例子学习C++的第三篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其大公约数. 解答方法一:两个数的最大公约数,是这两个数中的小数,或者是这2个数的公约数中的最大 ...
- nodeJs 5.0.0 安装配置与nodeJs入门例子学习
新手学习笔记,高手请自动略过 安装可以先看这篇:http://blog.csdn.net/bushizhuanjia/article/details/7915017 1.首先到官网去下载exe,或者m ...
随机推荐
- dhlin-vim-wiki
记录vim中常用的几个操作 入门指南 $ vimtutor vim中是区分大小写 vim中移动光标 h 向左移动 j 向下移动 k 向上移动 l 向右移动 其实使用方向键也是能移动的,但是熟悉后再一些 ...
- springboot集成PageHelper,支持springboot2.0以上版本
第一步:pom文件还是需要引入依赖 <!--mybatis的分页插件--> <dependency> <groupId>com.github.pagehelper& ...
- Synchronized 实现原理
记得刚刚开始学习Java的时候,一遇到多线程情况就是synchronized.对于当时的我们来说,synchronized是如此的神奇且强大.我们赋予它一个名字"同步",也成为我们 ...
- IntelliJ IDEA安装MongoDB的的数据操作插件
说明:只能说效果一般,没有Robo 3T那么好用. 参考: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206635 ...
- 受检查异常要求try catch,new对象时,就会在堆中创建内存空间,创建的空间包括各个成员变量类型所占用的内存空间
,new对象时,就会在堆中创建内存空间,创建的空间包括各个成员变量类型所占用的内存空间
- 用PHP实现弹出消息提示框
方法一: echo "<script>alert('提示内容')</script>"; 方法二: echo '<script language=&qu ...
- HTML小技巧将table边框改为细线
HTML制作新手在用TABLE表格时,会碰到如何改变边线粗线,因为默认的TABLE边线设置即使是1px 是很粗的.因此会使用其他一些方法来制作出细线边框,这里介绍一种利用CSS来实现细线的方法,很有效 ...
- java编程思想第四版第9章
练习3: public class MainTest { public static void main(String args[]){ Bcycle b=new Bcycle(); b.print( ...
- 微信开发token验证失败
遇到token验证时: 1.首先检验是否是80端口或443端口,能否接收到微信的响应信息,如果使用域名,域名要备注,否则接收不到响应信息: 2.其次判断是否能正常echo $echoStr,之前不能有 ...
- Mockito 库、powermock扩展
转载:http://blog.csdn.net/kittyboy0001/article/details/18709685 Mockito 简介 Mockito 是目前 java 单测中使用比较流行的 ...