Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 高级经理(姓名); theNode.ImageIndex:=-1;//没有文件的图像 结束; 直到FindNext(sr)0; FindClose(sr); 结束; FileTree.FullExpand; 结束;_Delphi_Treeview_Tree_Lazarus - Fatal编程技术网

Delphi 高级经理(姓名); theNode.ImageIndex:=-1;//没有文件的图像 结束; 直到FindNext(sr)0; FindClose(sr); 结束; FileTree.FullExpand; 结束;

Delphi 高级经理(姓名); theNode.ImageIndex:=-1;//没有文件的图像 结束; 直到FindNext(sr)0; FindClose(sr); 结束; FileTree.FullExpand; 结束;,delphi,treeview,tree,lazarus,Delphi,Treeview,Tree,Lazarus,要添加到表格中的附加程序 procedure TForm1.AddDirectories(theNode: tTreeNode; cPath: string); var sr: TSearchRec; FileAttrs: Integer; theNewNode : tTreeNode; begin FileAttrs := faDirectory; // Only care about directories if FindFirst(cPath+'\*.*',

要添加到表格中的附加程序

procedure TForm1.AddDirectories(theNode: tTreeNode; cPath: string);
var
  sr: TSearchRec;
  FileAttrs: Integer;
  theNewNode : tTreeNode;
begin
   FileAttrs := faDirectory;     // Only care about directories
   if FindFirst(cPath+'\*.*', FileAttrs, sr) = 0 then
    begin
      repeat
        if  ((sr.Attr and FileAttrs) = sr.Attr) and (copy(sr.Name,1,1) <> '.')
        then
        begin
            theNewNode := dirTree.Items.AddChild(theNode,sr.name);
            AddDirectories(theNewNode,cPath+'\'+sr.Name);
        end;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
end;
procedure TForm1.AddDirectories(theNode:tTreeNode;cPath:string);
变量
sr:TSearchRec;
FileAttrs:整数;
新节点:t新节点;
开始
FileAttrs:=faDirectory;//只关心目录
如果FindFirst(cPath+'\*.*',FileAttrs,sr)=0,则
开始
重复
如果((sr.Attr和FileAttrs)=sr.Attr)和(copy(sr.Name,1,1)')
然后
开始
theNewNode:=dirTree.Items.AddChild(theNode,sr.name);
AddDirectories(newnode,cPath+'\'+sr.Name);
结束;
直到FindNext(sr)0;
FindClose(sr);
结束;
结束;
您需要向表单中添加一个图像列表,向其中添加一个文件夹图标(borland common files中有一个),然后将图像列表与目录树视图和文件树树视图相关联

如何调用FILTEREDTV过程的示例

将以下代码附加到目录树的OnClick事件

procedure TForm1.DirTreeClick(Sender: TObject);
var
  cBuild : string;
  theNode : tTreeNode;
begin
    if DirTree.Selected <> nil then
    begin
        theNode := DirTree.Selected;
        cBuild := theNode.Text;
        while theNode.Parent <> nil do
        begin
            cBuild := theNode.Parent.Text+'\'+cBuild;
            theNode := theNode.Parent;
        end;
        cBuild := stringReplace(cBuild,'\\','\',[rfReplaceAll]);
        FilteredTV(cBuild,'pdf',nil);
    end;

end;
过程TForm1.DirTreeClick(发送方:TObject);
变量
cBuild:string;
节点:t节点;
开始
如果DirTree.Selected为nil,则
开始
节点:=DirTree.Selected;
cBuild:=theNode.Text;
而node.Parent nil do
开始
cBuild:=theNode.Parent.Text+'\'+cBuild;
theNode:=theNode.Parent;
结束;
cBuild:=stringReplace(cBuild,'\\','\',[rfReplaceAll]);
过滤数字电视(cBuild,'pdf',无);
结束;
结束;

好的,我误解了你的问题。您需要对每个目录进行递归调用。。。就性能而言,这可能会大大降低树逻辑的速度,因为您现在需要扫描硬盘的整个结构。我将为您修改上面的代码…我添加了一个示例,说明如何根据用户在目录树视图中单击的文件夹调用FilteredTV过程:
if(sr.Name.')和(sr.Name'..')然后开始
应在
if(sr.Attr和FileAttrs)=sr Attr然后开始
过程中的
,要排除
值,此过程实际上会在这些节点下加载数据。别以为你想要那样。它似乎也无缘无故地排除了许多目录。@Jerry Dodge-这是因为有多个小问题:#1。“(sr.Attr和FileAttrs)=sr.Attr)”-这只允许精确匹配-排除设置了其他属性位=应为“(sr.Attr和FileAttrs)=FileAttrs)”的有效文件夹(因此也允许只读、隐藏/etc文件夹)#2.“(copy(sr.Name,1,1)”。”)“不包括任何以dot=开头的dir,应该与您的评论相同。好吧,我误解了您的问题。您需要对每个目录进行递归调用。。。就性能而言,这可能会大大降低树逻辑的速度,因为您现在需要扫描硬盘的整个结构。我将为您修改上面的代码…我添加了一个示例,说明如何根据用户在目录树视图中单击的文件夹调用FilteredTV过程:
if(sr.Name.')和(sr.Name'..')然后开始
应在
if(sr.Attr和FileAttrs)=sr Attr然后开始
过程中的
,要排除
值,此过程实际上会在这些节点下加载数据。别以为你想要那样。它似乎也无缘无故地排除了许多目录。@Jerry Dodge-这是因为有多个小问题:#1。“(sr.Attr和FileAttrs)=sr.Attr)”-这只允许精确匹配-排除设置了其他属性位=应为“(sr.Attr和FileAttrs)=FileAttrs)”的有效文件夹(因此也允许只读、隐藏/etc文件夹)#2.“(copy(sr.Name,1,1)”。”)“排除任何以dot=开头的dir,应与您的注释中的内容相同。该图像链接到外部第三方源,该源似乎不再可用…该图像链接到外部第三方源,该源似乎不再可用。。。
procedure TForm1.AddDirectories(theNode: tTreeNode; cPath: string);
var
  sr: TSearchRec;
  FileAttrs: Integer;
  theNewNode : tTreeNode;
begin
   FileAttrs := faDirectory;     // Only care about directories
   if FindFirst(cPath+'\*.*', FileAttrs, sr) = 0 then
    begin
      repeat
        if  ((sr.Attr and FileAttrs) = sr.Attr) and (copy(sr.Name,1,1) <> '.')
        then
        begin
            theNewNode := dirTree.Items.AddChild(theNode,sr.name);
            AddDirectories(theNewNode,cPath+'\'+sr.Name);
        end;
      until FindNext(sr) <> 0;
      FindClose(sr);
    end;
end;
procedure TForm1.DirTreeClick(Sender: TObject);
var
  cBuild : string;
  theNode : tTreeNode;
begin
    if DirTree.Selected <> nil then
    begin
        theNode := DirTree.Selected;
        cBuild := theNode.Text;
        while theNode.Parent <> nil do
        begin
            cBuild := theNode.Parent.Text+'\'+cBuild;
            theNode := theNode.Parent;
        end;
        cBuild := stringReplace(cBuild,'\\','\',[rfReplaceAll]);
        FilteredTV(cBuild,'pdf',nil);
    end;

end;