首页 > 其他 > 详细

delphi 文件或目录转换成 TreeView

时间:2014-08-01 12:52:21      阅读:392      评论:0      收藏:0      [点我收藏+]



//文件或目录转换成 TreeView

procedure DirToTreeView(Tree: TTreeView; Directory: string; Root: TTreeNode; IncludeFiles:
  Boolean);
var
  SearchRec         : TSearchRec;
  ItemTemp          : TTreeNode;
begin
  with Tree.Items do
  try
    BeginUpdate;
    if Directory[Length(Directory)] <> ‘\‘ then Directory := Directory + ‘\‘;
    if FindFirst(Directory + ‘*.*‘, faDirectory, SearchRec) = 0 then
    begin
      repeat
        if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> ‘.‘) then
        begin
          if (SearchRec.Attr and faDirectory > 0) then
            Root := AddChild(Root, SearchRec.Name);
          ItemTemp := Root.Parent;
          DirToTreeView(Tree, Directory + SearchRec.Name, Root, IncludeFiles);
          Root := ItemTemp;
        end
        else if IncludeFiles then
          if SearchRec.Name[1] <> ‘.‘ then
            AddChild(Root, SearchRec.Name);
      until FindNext(SearchRec) <> 0;
      FindClose(SearchRec);
    end;
  finally
    EndUpdate;
  end;
end;


procedure TForm1.ToolButton7Click(Sender: TObject);
var
  node:TTreeNode;
begin
    node:=nil;//放在OnCreate下面可以正常
    DirToTreeView(TreeView1,‘Z:\‘,node,False);
end;




delphi 文件或目录转换成 TreeView,布布扣,bubuko.com

delphi 文件或目录转换成 TreeView

原文:http://www.cnblogs.com/xe2011/p/3884327.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!