当前位置:编程文档 >> DELPHI >> Delphi 4中TTreeView的bug
首页

Delphi 4中TTreeView的bug

所属类别:DELPHI
推荐指数:★★☆
文档人气:21
本周人气:1
发布日期:2007-5-11

假设我们要将某个结点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;

文档说明:

     

相关文档


读取评论列表……