过程如下:
procedure TfrmClientMng.ActBuildTree;
var
rootNode,subnode,childNode:TTreeNode;
showstr,datastr,smallshow,smallno:string;
begin
inherited;
TVClient.Items.Clear;
rootNode:=nil;
RootNode := TVClient.Items.AddObject(Nil,'所有',pointer('0'));
rootnode.ImageIndex:= 16;
rootnode.SelectedIndex:=16;
dmpact.ADOAreabig.First;
while not dmpact.ADOAreabig.Eof do
begin
datastr:=pchar(dmpact.ADOAreabig.FieldByName('areacode').Asstring);
showstr:=dmpact.ADOAreabig.FieldByName('areaname').AsString;
subnode:=TVClient.Items.Addchildobject(rootNode,showstr,pointer(datastr));
SubNode.ImageIndex := 12;
SubNode.SelectedIndex := 13;
DMpact.ADOAreasmall.First;
showmessage(pchar(subNode.Data)^+'out while');///////外循环data始终有值
while not DMpact.ADOAreasmall.Eof do
begin
smallshow:=DMpact.ADOAreasmallAREAITEM.AsString;
datastr:=Dmpact.ADOAreasmallAREATYPE.AsString;
childNode:=TVClient.Items.Addchildobject(subNode,smallshow,pointer(datastr));
childNode.ImageIndex := 12;
childNode.SelectedIndex := 13;
DMpact.ADOAreasmall.Next;
showmessage(pchar(subNode.Data)^+'in while'); /////内循环data 一会儿有一会儿没有
end;
dmpact.adoareabig.Next;
end;
end;
////为什么data值保存不上呢???,外循环,增加一个,立马可看到,到了内循环,这个数据就偶尔能看,偶尔不能了,为什么,所有结点的text都有,treeview也出来了,就是这个data数据好像存不上,造成我取的时候,出了很多问题,到底哪里错了,谢谢指教???
procedure TfrmClientMng.ActBuildTree;
var
rootNode,subnode,childNode:TTreeNode;
showstr,datastr,smallshow,smallno:string;
begin
inherited;
TVClient.Items.Clear;
rootNode:=nil;
RootNode := TVClient.Items.AddObject(Nil,'所有',pointer('0'));
rootnode.ImageIndex:= 16;
rootnode.SelectedIndex:=16;
dmpact.ADOAreabig.First;
while not dmpact.ADOAreabig.Eof do
begin
datastr:=pchar(dmpact.ADOAreabig.FieldByName('areacode').Asstring);
showstr:=dmpact.ADOAreabig.FieldByName('areaname').AsString;
subnode:=TVClient.Items.Addchildobject(rootNode,showstr,pointer(datastr));
SubNode.ImageIndex := 12;
SubNode.SelectedIndex := 13;
DMpact.ADOAreasmall.First;
showmessage(pchar(subNode.Data)^+'out while');///////外循环data始终有值
while not DMpact.ADOAreasmall.Eof do
begin
smallshow:=DMpact.ADOAreasmallAREAITEM.AsString;
datastr:=Dmpact.ADOAreasmallAREATYPE.AsString;
childNode:=TVClient.Items.Addchildobject(subNode,smallshow,pointer(datastr));
childNode.ImageIndex := 12;
childNode.SelectedIndex := 13;
DMpact.ADOAreasmall.Next;
showmessage(pchar(subNode.Data)^+'in while'); /////内循环data 一会儿有一会儿没有
end;
dmpact.adoareabig.Next;
end;
end;
////为什么data值保存不上呢???,外循环,增加一个,立马可看到,到了内循环,这个数据就偶尔能看,偶尔不能了,为什么,所有结点的text都有,treeview也出来了,就是这个data数据好像存不上,造成我取的时候,出了很多问题,到底哪里错了,谢谢指教???
subNode.Data := strnew('asdf');
在树释放时,
strdispose(subnode.data);