delphi文件搜索多线程

前端之家收集整理的这篇文章主要介绍了delphi文件搜索多线程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我执行它,我的应用程序将不会响应,直到找到所有文件和他们到列表框
我的问题是如何使这个功能多线程,以避免不相应的情况!我仍然是Delphi novoice
  1. procedure TfrMain.FileSearch(const PathName,FileName : string; txtToSearch : string; const InDir : boolean);
  2. var Rec : TSearchRec;
  3. Path : string;
  4. txt : string;
  5. fh : TextFile;
  6. i : integer;
  7. begin
  8.  
  9.  
  10. Path := IncludeTrailingBackslash(PathName);
  11. if FindFirst(Path + FileName,faAnyFile - faDirectory,Rec) = 0 then
  12. try
  13. repeat
  14.  
  15. AssignFile(fh,Path + Rec.Name);
  16. Reset(fh);
  17. Readln(fh,txt);
  18.  
  19. if ContainsStr(txt,txtToSearch) then
  20. ListBox1.Items.Add(Path + Rec.Name);
  21.  
  22. until FindNext(Rec) <> 0;
  23. finally
  24. FindClose(Rec);
  25.  
  26. end;
  27.  
  28. If not InDir then Exit;
  29.  
  30. if FindFirst(Path + '*.*',faDirectory,Rec) = 0 then
  31. try
  32. repeat
  33. if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..') then
  34. FileSearch(Path + Rec.Name,FileName,txtToSearch,True);
  35. until FindNext(Rec) <> 0;
  36. finally
  37. FindClose(Rec);
  38. end;
  39. end;

解决方法

Here您可以找到有关使用 OmniThreadLibrary实现的后台文件扫描程序的文章.

猜你在找的Delphi相关文章