//分析虚拟树demo
6-VirtualTreeView\VirtualTreeViewV5.3.0\Demos\Minimal的main.pas文件

unit Main;

// Demonstration project for TVirtualStringTree to generally show how to get started.
// Written by Mike Lischke.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
VirtualTrees, StdCtrls, ExtCtrls;
type
TMainForm = class(TForm)
VST: TVirtualStringTree;
ClearButton: TButton;
AddOneButton: TButton;
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
CloseButton: TButton;
procedure FormCreate(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType; var Text: UnicodeString);
procedure VSTFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VSTInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
procedure CloseButtonClick(Sender: TObject);
procedure VSTStartDrag(Sender: TObject; var DragObject: TDragObject);
end; var
MainForm: TMainForm;
//----------------------------------------------------------------------------------------------------------------------
implementation
{$R *.DFM}
type
// This is a very simple record we use to store data in the nodes.
// Since the application is responsible to manage all data including the node's caption
// this record can be considered as minimal requirement in all VT applications.
// Extend it to whatever your application needs.
PMyRec = ^TMyRec;
TMyRec = record
Caption: WideString;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.FormCreate(Sender: TObject);
begin
// We assign the OnGetText handler manually to keep the demo source code compatible
// with older Delphi versions after using UnicodeString instead of WideString.
VST.OnGetText := VSTGetText;
// Let the tree know how much data space we need.
VST.NodeDataSize := SizeOf(TMyRec); //设定一个node的内存大小,虚拟树的妙处
// Set an initial number of nodes.
VST.RootNodeCount := ;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.ClearButtonClick(Sender: TObject);
var
Start: Cardinal;
begin
Screen.Cursor := crHourGlass;
try
Start := GetTickCount;
VST.Clear;
Label1.Caption := Format('Last operation duration: %d ms', [GetTickCount - Start]);
finally
Screen.Cursor := crDefault;
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.AddButtonClick(Sender: TObject);
var
Count: Cardinal;
Start: Cardinal;
begin
// Add some nodes to the treeview.
Screen.Cursor := crHourGlass;
with VST do
try
Start := GetTickCount;
case (Sender as TButton).Tag of
: // add to root
begin
Count := StrToInt(Edit1.Text);
RootNodeCount := RootNodeCount + Count;//自动改变这个属性即可
end;
: // add as child
if Assigned(FocusedNode) then
begin
Count := StrToInt(Edit1.Text);
ChildCount[FocusedNode] := ChildCount[FocusedNode] + Count;
Expanded[FocusedNode] := True;
InvalidateToBottom(FocusedNode);//要放到后面
end;
end;
Label1.Caption := Format('Last operation duration: %d ms', [GetTickCount - Start]);
finally
Screen.Cursor := crDefault;
end;
end; //----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType; var Text: UnicodeString);
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.
// OnGetText事件处理程序总是需要为它提供了树显示的字符串数据。
//注意,我们总是使用WideString。
Data := Sender.GetNodeData(Node);//虚拟树的取值
if Assigned(Data) then
Text := Data.Caption;
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.
///影响自由的字符串,VCL无法知道有一个但仍然需要自由。
//为多个字段的记录必须释放使用Finalize(数据^)而不是单独触摸每一个成员。
Finalize(Data^);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.VSTInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates);
var
Data: PMyRec;
begin
with Sender do
begin
Data := GetNodeData(Node);
// Construct a node caption. This event is triggered once for each node but
// appears asynchronously, which means when the node is displayed not when it is added.
//构造一个节点标题。这个事件触发异步为每个节点,但一旦出现,这意味着当节点添加时不显示。 每次初始化时都会给这样的值
Data.Caption := Format('Level %d, Index %d', [GetNodeLevel(Node), Node.Index]);
end;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.CloseButtonClick(Sender: TObject);
begin
Close;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TMainForm.VSTStartDrag(Sender: TObject; var DragObject: TDragObject);
begin
DragObject := TDragObject.Create;
end;
//----------------------------------------------------------------------------------------------------------------------
end.

最新文章

  1. Map排序
  2. exit
  3. [.net 面向对象编程基础] (11) 面向对象三大特性——封装
  4. 怎么学习AOPR使用方法
  5. Solr安装入门、查询详解
  6. AD批量创建用户
  7. ubuntu使用root账户登录
  8. uva 816 Abbott的复仇
  9. MySql事务及JDBC对事务的使用
  10. 两个div之间有空隙
  11. 树莓派设置固定ip
  12. Swift3.0服务端开发(四) MySQL数据库的连接与操作
  13. [图形学] Chp9 三维几何变换--栈处理函数与矩阵管理函数的区别
  14. Struts2学习笔记(十一)——文件上传
  15. matlab中 mcc/mbuild/mex 区别
  16. spring 相关注解详情(二)
  17. 微信小程序——地图
  18. iOS----KVC和KVO 详解
  19. [CF1137E]Train Car Selection[维护凸壳]
  20. dreamweavercs 和dreamweaver cc的區別

热门文章

  1. Spring单例模式与线程安全
  2. 一、Daily Scrum Meeting【Alpha】------Clover
  3. Java+jquery实现裁剪图片上传到服务器
  4. <<< tomcat启动报错StandardServer.await: create[8005]
  5. HDU 1817Necklace of Beads(置换+Polya计数)
  6. QQ空间爬虫最新分享,一天 400 万条数据(附代码地址)
  7. 初识Docker和Windows Server容器
  8. windows7下修改hosts文件无效解决办法(转)
  9. asp.net core 使用EF7 Code First 创建数据库,同时使用命令创建数据库
  10. eclipse version