www.pudn.com > Delphi-TreeLsit.rar > Unit1.pas, change:2011-09-06,size:7548b


unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ComCtrls, StdCtrls, ImgList, Math, TreeList, CommCtrl, ExtCtrls, 
  XPMan, StrUtils; 
 
const 
  WM_TEST001 = WM_USER + 200; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Button2: TButton; 
    TreeList1: TTreeList; 
    XPManifest1: TXPManifest; 
    Button5: TButton; 
    Button6: TButton; 
    ImageList1: TImageList; 
    Button9: TButton; 
    Button10: TButton; 
    Button12: TButton; 
    Button13: TButton; 
    Button14: TButton; 
    procedure Button10Click(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
    procedure Button3Click(Sender: TObject); 
    procedure Button4Click(Sender: TObject); 
    procedure Button7Click(Sender: TObject); 
    procedure Button8Click(Sender: TObject); 
    procedure Button9Click(Sender: TObject); 
    procedure TreeList1Change(Sender: TObject; Node: TTreeNode); 
    procedure Button2Click(Sender: TObject); 
    procedure Button5Click(Sender: TObject); 
    procedure Button12Click(Sender: TObject); 
    procedure Button13Click(Sender: TObject); 
    procedure TreeList1Deletion(Sender: TObject; Node: TTreeNode); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form1: TForm1; 
 
 
implementation 
 
//uses Unit2; 
 
{$R *.dfm} 
 
 
type 
  _testrecord = record 
    a: integer; 
    b: string; 
    c: byte; 
    d: string; 
  end; 
 
  _testrecord2 = record 
    a: integer; 
    b: array[0..$FFFFFF] of char; 
  end; 
 
// 内存释放测试通过 
procedure TForm1.Button10Click(Sender: TObject); 
var 
  node: TTreeNode; 
  p: pchar; 
  len,k: integer; 
  p2: ^_TestRecord2; 
  p3: Pointer; 
begin 
  k:= 0; 
  node:= Treelist1.GetFirstNode; 
  while node <> nil do begin 
    len:= $4FFFFF; 
    GetMem(p3, len); 
    ZeroMemory(p3, len); 
    Treelist1.SetItemData(node, p3, false); 
    node:= node.GetNext; 
    Inc(k); 
  end; 
  showmessage(inttostr(k)); 
 
{ 
  new(p2); 
  ZeroMemory(p2, SizeOf(_TestRecord2)); 
  MessageBox(handle, 'Next', '', 0); 
  //dispose(p2); 
  FreeMem(p2);     // 可以互换释放内存 
} 
 
{ 
  GetMem(p2, SizeOf(_TestRecord)); 
  p2.a := 1; 
  p2.b:= 'dfsdf';   // Exception 
  p2.c:= 33; 
  p2.d := '234'; 
  FreeMem(p2); 
} 
 
{ 
  len:= $FFFFFF; 
  GetMem(p3, len); 
  ZeroMemory(p3, len); 
 
  showmessage('Next'); 
  Dispose(p3);          // 这个也可以互换释放内存 
  //FreeMem(p); 
  //p:= nil; 
} 
end; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var 
  node: TTreenode; 
  i: integer; 
begin 
 
  treelist1.SetCheckImageIndex(3, 4, 0, 0); 
 
  node:= TreeList1.AddRoot('ITEM  AAAAAAAAA', 0); 
  TreeList1.AddCheckChild(node, '1111111111111111111111111111111111111111111' + #1 + '2222222' + #1 + '333333'); 
  TreeList1.AddCheckChild(node, '222222222' + #1 + '333333333' + #1 + '111111'); 
  treelist1.Expand(node); 
 
  node:= TreeList1.AddRoot('ITEM  BBBBBBBB WDJJUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU', 0); 
  TreeList1.AddCheckChild(node, 'CCCC' + #1 + 'FFFF' + #1 + 'WWWWWWWWWWWW'); 
  TreeList1.AddCheckChild(node, 'DDDDDD' + #1 + 'EEEEE' + #1 + 'FFFFF'); 
  treelist1.Expand(node); 
  node:= TreeList1.AddRoot('ITEM  CCCCCCCC', 2); 
  TreeList1.AddChild(node, '%%%%%%%' + #1 + '^^' + #1 + '##################################'); 
  TreeList1.AddChild(node, '@@@@@@@@@@@@@' + #1 + '$$$$$' + #1 + '&&&&&&&'); 
  treelist1.Expand(node); 
 
  node:= TreeList1.AddRoot('ITEM  AAAAAAAAA', 1); 
  TreeList1.AddCheckChild(node, '1111111111111111111111111111111111111111111' + #1 + '2222222' + #1 + '333333'); 
  TreeList1.AddCheckChild(node, '555' + #1 + '11111' + #1 + '0000000000000000000'); 
  treelist1.Expand(node); 
  node:= TreeList1.AddRoot('ITEM  BBBBBBBB', 1); 
  TreeList1.AddCheckChild(node, 'DDDDDD' + #1 + 'HHHHH' + #1 + 'FFFFF'); 
  TreeList1.AddCheckChild(node, 'AAAAA' + #1 + 'EEEEE' + #1 + 'RRRRRRR'); 
  treelist1.Expand(node); 
  node:= TreeList1.AddRoot('ITEM  CCCCCCCC', 2); 
  TreeList1.AddChild(node, '#####' + #1 + '$$$$$' ); 
  TreeList1.AddChild(node, '@@@@@@@@@@@@@' + #1 + '@@@@@@@@@' ); 
  treelist1.Expand(node); 
 
  node:= TreeList1.AddChild(node, '123' ); 
  TreeList1.AddNodeText(node, ''); 
  TreeList1.AddNodeText(node, '456'); 
 
 
 
  //treelist1.tv.Images := ImageList1 ; 
  //treelist1.CheckItemByDoubleClick := false; 
 
//  TreeList1.UpdateColumns; 
 
//  for i:= 0 to TreeList1.tv.Items.Count - 1 do 
//    TreeList1.tv.Items[I].Expand(false); 
 
 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  node: TTreeNode; 
  i: word; 
begin 
  treelist1.AddHeaderItem('COMMENT', 80); 
  treelist1.AddHeaderItem('COMMENT', 120); 
  treelist1.AddHeaderItem('COMMENT', 90); 
 
{ 
  i:= 64; 
  showmessage(inttostr((not i))); 
 
{ 
  node:= treelist1.tv.Selected ; 
  if node <> nil then 
    treelist1.tv.DeleteItem(node); 
} 
end; 
 
procedure TForm1.Button3Click(Sender: TObject); 
var 
  a1,a2: integer; 
begin 
  //showmessage(Format('%d, %d, %d', [TreeList1.Width, TreeList1.hdr.Width, TreeList1.tv.Width ])); 
  showmessage(format('%d, %d, %d, %d', [GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER), GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)]));  
 
end; 
 
procedure TForm1.Button4Click(Sender: TObject); 
begin 
//  showmessage(format('%d, %d', [panel1.Height, panel1.ClientHeight])); 
end; 
 
procedure TForm1.Button7Click(Sender: TObject); 
var 
  node: TTreeNode; 
  s: string; 
  i: integer; 
begin 
  s:= ''; 
  for i:= ord('A') to ord('T') do 
    s:= s + '1234567890 ' + chr(i) + ' '; 
 
end; 
 
procedure TForm1.Button8Click(Sender: TObject); 
var 
  s: string; 
  node: TTreeNode; 
begin 
end; 
 
procedure TForm1.Button9Click(Sender: TObject); 
var 
  hAxtMap: THandle; 
  hAxtBuffer: pchar; 
  s: string; 
begin 
 
end; 
 
 
procedure TForm1.TreeList1Change(Sender: TObject; Node: TTreeNode); 
begin 
//  showmessage(node.Text ); 
end; 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
  treelist1.__Test; 
//  treelist1.HeaderSections.Add.Text:= 'TTTTTTT'; 
  //treelist1.SetHeaderItem(1, 'test'); 
  //showmessage(inttostr(treelist1.GetRootNodeCount )); 
end; 
 
procedure TForm1.Button5Click(Sender: TObject); 
var 
  node: TTreenode; 
begin 
  node:= treelist1.GetLastNode; 
  node:= node.getPrevSibling; 
  treelist1.AddNodeText(node, 'test'); 
  node:= node.getPrevSibling; 
  treelist1.SetNodeText(node, 'SSSSSSS', 1); 
end; 
 
const 
  _Seperator = #1; 
   
procedure TForm1.Button12Click(Sender: TObject); 
var 
  k: integer; 
  s: string; 
begin 
end; 
 
procedure TForm1.Button13Click(Sender: TObject); 
var 
  node: TTreeNode; 
begin 
  node:= TreeList1.GetFirstNode; 
  node.StateIndex := 4; 
  showmessage('Next'); 
  node.StateIndex := -1; 
 
{ 
  node:= TreeList1.GetFirstNode; 
  node:= node.getFirstChild; 
  TreeList1.DeleteNode(node); 
  //TreeList1.AddNodeText(node, 'aa'); 
  node:= node.getNextSibling; 
  if node <> nil then 
    showmessage(Inttostr(node.Index)); 
 
 
{ 
  node.Delete; 
  node.Delete; 
{ 
  //showmessage(treelist1.GetHeaderItemText(1)); 
  //showmessage(inttostr(treelist1.GetRootNodeCount)); 
  treelist1.GoTop; 
 
  node:= treelist1.GetSelNode; 
  //if node = nil then exit; 
 
  showmessage(Inttostr( Treelist1.GetCheckCountAll( true ))); 
} 
end; 
 
procedure TForm1.TreeList1Deletion(Sender: TObject; Node: TTreeNode); 
var 
  p: pointer; 
begin 
  p:= TreeList1.GetItemData(node); 
  FreeMem(p); 
end; 
 
end.