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 ...
随机推荐
- Akka之Circuit Breaker
这周在项目中遇到了一个错误,就是Circuit Breaker time out.以前没有接触过,因此学习了下akka的断路器. 一.为什么使用Circuit Breaker 断路器是为了防止分布式系 ...
- webservice测试窗体只能用于来自本地计算机的请求
写在前面 在编写好webservice后,发布到iis服务器,你会发现会有这样的异常“测试窗体只能用于来自本地计算机的请求”. 解决方案 在web.config中添加以下代码即可解决问题 <we ...
- 【Objective-C Runtime动态加载】---动态创建类Class
a.使用objc_allocateClassPair创建一个类Class const char * className = "Calculator"; Class kc ...
- 读取配置文件包含properties和xml文件
读取properties配置文件 /** * 读取配置文件 * @author ll-t150 */ public class Utils { private static Properties pr ...
- Linux学习之十九-Linux磁盘管理
Linux磁盘管理 1.相关知识 磁盘,是计算机硬件中不可或缺的部分磁盘,是计算机的外部存储器中类似磁带的装置,将圆形的磁性盘片装在一个方的密封盒子里,这样做的目的是为了防止磁盘表面划伤,导致数据丢失 ...
- 又一次遇到Data truncation: Data too longData truncation: Data too long问题
往MySQL的blob字段上传文件,结果又出现了Data truncation: Data too longData truncation: Data too long异常. 我的第一反应是查看/et ...
- JavaScript学习与实践一
一.JavaScript数组 创建JavaScript数组有两种方式 方式一: var cars=new Array(); cars[0]="Audi"; cars[1]=&quo ...
- Oracle中group by 的扩展函数rollup、cube、grouping sets
Oracle的group by除了基本使用方法以外,还有3种扩展使用方法,各自是rollup.cube.grouping sets.分别介绍例如以下: 1.rollup 对数据库表emp.如果当中两个 ...
- Node.js学习笔记(2)——关于异步编程风格
Node.js的异步编程风格是它的一大特点,在代码中就是体现在回调中. 首先是代码的顺序执行: function heavyCompute(n, callback) { var count = 0, ...
- C# Excel
using System.IO;using System.Text;namespace iLIS.Common{ ///<summary> ///生成Excel文档内容 /// 存入工作流 ...