一、保存记录类型在data指针中:
procedure TForm1.getheaditems(pp:TfrxBand;hnode:THeadTreeNode;var i:Integer;var j:Integer;var zh,tmph:Integer;var tree:TTreeView);
type
Trec=record
text:string;
left,top,width,height:Integer;
end;
TPRec = ^TRec;
var
h,lh,w,tp,lt,m,firstp:Integer;
ht:THeadTreeNode;
currentnode,pnode:TTreeNode;
hh,ss,firsttext:string;
ntrec:TPrec;
begin
firsttext:=hnode.Text;
ht:=hnode;
m:=0;
while True do
begin
w:=ht.Width;
New(ntrec);
if w>0 then
begin
hh:=ht.Text;
lh:=ht.GetLevel;
h:=ht.Height;
if lh=1 then
i:=0;
//ss:='left:'+inttostr(j)+',top:'+inttostr(i)+',h:'+inttostr(h)+',w:'+inttostr(w)+',text:'+hh+',level:'+inttostr(lh);
//Memo1.Lines.Add(ss);
//build tree
if lh=1 then
currentnode:=tree.Items.Add(nil,hh)
else
begin
pnode:=findtreeitem(tree,ht.Host.Text);
currentnode:=tree.Items.AddChild(pnode,hh);
end;
ntrec^.text:=hh;
ntrec^.Top:=i;
ntrec^.Left:=j;
ntrec^.Width:=w;
ntrec^.Height:=h;
currentnode.Data:=ntrec;//CreateMemoFun(pp,hh,'leftcolumns',baNone,nil,'',j, i, w, h);
//ntrec:=TPRec(currentnode.Data);
with ntrec^ do
begin
ss:='nodename:'+hh+',left:'+inttostr(left)+',top:'+inttostr(top)+','+inttostr(width)+',height:'+inttostr(Height)+',level:'+inttostr(lh);
end;
Memo1.Lines.Add(ss);
if m=0 then
firstp:=i
else
i:=firstp;
end else //跳过不可见列
w:=0;
if Assigned(ht.Child) then
begin
//tmph:=i;
i:=i+h;
getheaditems(pp,ht.Child,i,j,zh,tmph,tree);
end else
begin
j:=j+w;
zh:=i+h;
//i:=tmph;
end;
ht:=ht.Next;
m:=m+1;
if ht.Text=firsttext then
begin
Break;
end;
end;
end;
type
Trec=record
text:string;
left,top,width,height:Integer;
end;
TPRec = ^TRec;
var
h,lh,w,tp,lt,m,firstp:Integer;
ht:THeadTreeNode;
currentnode,pnode:TTreeNode;
hh,ss,firsttext:string;
ntrec:TPrec;
begin
firsttext:=hnode.Text;
ht:=hnode;
m:=0;
while True do
begin
w:=ht.Width;
New(ntrec);
if w>0 then
begin
hh:=ht.Text;
lh:=ht.GetLevel;
h:=ht.Height;
if lh=1 then
i:=0;
//ss:='left:'+inttostr(j)+',top:'+inttostr(i)+',h:'+inttostr(h)+',w:'+inttostr(w)+',text:'+hh+',level:'+inttostr(lh);
//Memo1.Lines.Add(ss);
//build tree
if lh=1 then
currentnode:=tree.Items.Add(nil,hh)
else
begin
pnode:=findtreeitem(tree,ht.Host.Text);
currentnode:=tree.Items.AddChild(pnode,hh);
end;
ntrec^.text:=hh;
ntrec^.Top:=i;
ntrec^.Left:=j;
ntrec^.Width:=w;
ntrec^.Height:=h;
currentnode.Data:=ntrec;//CreateMemoFun(pp,hh,'leftcolumns',baNone,nil,'',j, i, w, h);
//ntrec:=TPRec(currentnode.Data);
with ntrec^ do
begin
ss:='nodename:'+hh+',left:'+inttostr(left)+',top:'+inttostr(top)+','+inttostr(width)+',height:'+inttostr(Height)+',level:'+inttostr(lh);
end;
Memo1.Lines.Add(ss);
if m=0 then
firstp:=i
else
i:=firstp;
end else //跳过不可见列
w:=0;
if Assigned(ht.Child) then
begin
//tmph:=i;
i:=i+h;
getheaditems(pp,ht.Child,i,j,zh,tmph,tree);
end else
begin
j:=j+w;
zh:=i+h;
//i:=tmph;
end;
ht:=ht.Next;
m:=m+1;
if ht.Text=firsttext then
begin
Break;
end;
end;
end;
二、消除记录类型:
procedure TForm1.Button5Click(Sender: TObject);
type
Trec=record
text:string;
left,top,width,height:Integer;
end;
TPRec = ^TRec;
var
tnode,fn:THeadTreeNode;
level,ss:string;
i:Integer;
begin
with TreeView1 do
begin
for I := 0 to Items.Count-1 do
begin
level:=IntToStr(items[i].Level);
if assigned(TPRec(items[i].Data)) then
begin
dispose(TPRec(items[i].Data));
Memo1.Lines.Add('已释放指针:'+items[i].Text);
end;
ss:='nodename:'+items[i].Text+',level:'+level+',sn:'+inttostr(i);
Memo1.Lines.Add(ss);
end;
end;
end;
type
Trec=record
text:string;
left,top,width,height:Integer;
end;
TPRec = ^TRec;
var
tnode,fn:THeadTreeNode;
level,ss:string;
i:Integer;
begin
with TreeView1 do
begin
for I := 0 to Items.Count-1 do
begin
level:=IntToStr(items[i].Level);
if assigned(TPRec(items[i].Data)) then
begin
dispose(TPRec(items[i].Data));
Memo1.Lines.Add('已释放指针:'+items[i].Text);
end;
ss:='nodename:'+items[i].Text+',level:'+level+',sn:'+inttostr(i);
Memo1.Lines.Add(ss);
end;
end;
end;