码迷,mamicode.com
首页 > 其他好文 > 详细

delphi 文件或目录转换成 TreeView

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

标签:http   color   os   文件   for   ar   div   file   




//文件或目录转换成 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   color   os   文件   for   ar   div   file   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!