Delphi 4中TTreeView的bug
【打印文章】
假设我们要将某个结点treenode移动到另一结点AnItem上并做为AnItem的child,按照文档说明,只需这样做
TreeNode.moveto(AnItem,nrAddChild);
但实际上,在Delphi 4中,假如anode原来没有child的话,这条语句将不做任何事情。折衷的办法是
TempNode:=TopicTV.items.AddChild(AnItem,'');
TreeNode.MoveTo(TempNode, naInsert);
TempNode.free;
在Tipexplr程序的源码中,关于实现同样操作,它指出,Delphi的TTreeView有bug,并提供了自己的解决方法(见下),但这只能在Delphi 3中通过,在Delphi 4中,只能用我的上面的方法。
AttachMode := naAddChild; { Add tip as a child of category }
{ Note: Adding the temporary node is a work around to a bug }
{ that exists in the TreeView component when moving a }
{ node to a another node that doesn't have any children }
TempNode := TvwTips.Items.AddChild( TvwTips.DropTarget,'Temp' );
try
{ Move the node in the tree view }
TvwTips.Selected.MoveTo( TvwTips.DropTarget, AttachMode );
{ Now need to update the category of tip in the database }
TblTips.DisableControls;
try
TblTips.Edit;
TblTips[ 'Category' ] := TvwTips.DropTarget.Text;
TblTips.Post;
finally
TblTips.EnableControls;
end;
finally
TempNode.Free; { Don't forget to release the temp node }
end;
TreeNode.moveto(AnItem,nrAddChild);
但实际上,在Delphi 4中,假如anode原来没有child的话,这条语句将不做任何事情。折衷的办法是
TempNode:=TopicTV.items.AddChild(AnItem,'');
TreeNode.MoveTo(TempNode, naInsert);
TempNode.free;
在Tipexplr程序的源码中,关于实现同样操作,它指出,Delphi的TTreeView有bug,并提供了自己的解决方法(见下),但这只能在Delphi 3中通过,在Delphi 4中,只能用我的上面的方法。
AttachMode := naAddChild; { Add tip as a child of category }
{ Note: Adding the temporary node is a work around to a bug }
{ that exists in the TreeView component when moving a }
{ node to a another node that doesn't have any children }
TempNode := TvwTips.Items.AddChild( TvwTips.DropTarget,'Temp' );
try
{ Move the node in the tree view }
TvwTips.Selected.MoveTo( TvwTips.DropTarget, AttachMode );
{ Now need to update the category of tip in the database }
TblTips.DisableControls;
try
TblTips.Edit;
TblTips[ 'Category' ] := TvwTips.DropTarget.Text;
TblTips.Post;
finally
TblTips.EnableControls;
end;
finally
TempNode.Free; { Don't forget to release the temp node }
end;
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】