Z
zythuman
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的函数从一个xml文件读取内容在TTreeview中显示
procedure LoadChannellistToTreeView(inxmldoc:TXmldocument;channeltreeview:Ttreeview);
var
channellistnode:IXMLNode;
channelgroupnode:IXMLNode;
channelnode:IXMLNode ;
channelpropretynode:IXMLNode;
superroot:TTreeNode;
rootnode:TTreeNode ;
childnode:TTreeNode;
subscrichannel:Tsubscrichannel;//Tsubscrichannel 是自定义的类型它有一个属性feedlink
pointsubscrichannelsubscrichannel;//Psubscrichannel 是指向Tsubscrichannel类型的指针
begin
InXMLDoc.LoadFromFile('./channellist/channel.xml');
channellistnode:=InXMLDoc.DocumentElement;
channelgroupnode:= channellistnode.ChildNodes.First;
while(channelgroupnode<>nil )
do
begin
rootnode:=channeltreeview.Items.add(nil,channelgroupnode.Attributes['name']);
channelnode:=channelgroupnode.ChildNodes.First;
while(channelnode<>nil)
do
begin
channelpropretynode:=channelnode.ChildNodes.First;
while(channelpropretynode<>nil)
do
begin
if channelpropretynode.nodename='name'
then
childnode:=channeltreeview.items.addchild(rootnode,channelpropretynode.Text);
if channelpropretynode.nodename='feedlink'
then
begin
subscrichannel:=Tsubscrichannel.Create;
subscrichannel.feedlink:=channelpropretynode.Text;
pointsubscrichannel:=@subscrichannel;
childnode.Data:=Pointer(pointsubscrichannel);
end;
channelpropretynode:=channelpropretynode.NextSibling;
end;
channelnode:=channelnode.NextSibling;
end;
channelgroupnode:=channelgroupnode.NextSibling;
end;
end;
显示没问题但是所有的channelnode的data属性指向的Tsubscrichannel的feedlink值都相同
调试了很长时间也没找出毛病来,请各位大侠指点一下,谢谢!
xml文件的格式是这样的:
<?xml version="1.0" encoding="GB2312"?>
<chanellist>
<chanelgroup name="新闻">
<chanel >
<name>
新浪新闻
</name>
<feedlink>
http://rss.sina.com.cn/news/marquee/ddt.xml
</feedlink>
</chanel>
</chanelgroup>
<chanelgroup name="博客">
<chanel >
<name>
博客中国
</name>
<feedlink>
http://www.blogchina.com/xml/13_rss2.xml
</feedlink>
</chanel>
</chanelgroup>
</chanellist>
procedure LoadChannellistToTreeView(inxmldoc:TXmldocument;channeltreeview:Ttreeview);
var
channellistnode:IXMLNode;
channelgroupnode:IXMLNode;
channelnode:IXMLNode ;
channelpropretynode:IXMLNode;
superroot:TTreeNode;
rootnode:TTreeNode ;
childnode:TTreeNode;
subscrichannel:Tsubscrichannel;//Tsubscrichannel 是自定义的类型它有一个属性feedlink
pointsubscrichannelsubscrichannel;//Psubscrichannel 是指向Tsubscrichannel类型的指针
begin
InXMLDoc.LoadFromFile('./channellist/channel.xml');
channellistnode:=InXMLDoc.DocumentElement;
channelgroupnode:= channellistnode.ChildNodes.First;
while(channelgroupnode<>nil )
do
begin
rootnode:=channeltreeview.Items.add(nil,channelgroupnode.Attributes['name']);
channelnode:=channelgroupnode.ChildNodes.First;
while(channelnode<>nil)
do
begin
channelpropretynode:=channelnode.ChildNodes.First;
while(channelpropretynode<>nil)
do
begin
if channelpropretynode.nodename='name'
then
childnode:=channeltreeview.items.addchild(rootnode,channelpropretynode.Text);
if channelpropretynode.nodename='feedlink'
then
begin
subscrichannel:=Tsubscrichannel.Create;
subscrichannel.feedlink:=channelpropretynode.Text;
pointsubscrichannel:=@subscrichannel;
childnode.Data:=Pointer(pointsubscrichannel);
end;
channelpropretynode:=channelpropretynode.NextSibling;
end;
channelnode:=channelnode.NextSibling;
end;
channelgroupnode:=channelgroupnode.NextSibling;
end;
end;
显示没问题但是所有的channelnode的data属性指向的Tsubscrichannel的feedlink值都相同
调试了很长时间也没找出毛病来,请各位大侠指点一下,谢谢!
xml文件的格式是这样的:
<?xml version="1.0" encoding="GB2312"?>
<chanellist>
<chanelgroup name="新闻">
<chanel >
<name>
新浪新闻
</name>
<feedlink>
http://rss.sina.com.cn/news/marquee/ddt.xml
</feedlink>
</chanel>
</chanelgroup>
<chanelgroup name="博客">
<chanel >
<name>
博客中国
</name>
<feedlink>
http://www.blogchina.com/xml/13_rss2.xml
</feedlink>
</chanel>
</chanelgroup>
</chanellist>