如果我执行它,我的应用程序将不会响应,直到找到所有文件和他们到列表框
我的问题是如何使这个功能多线程,以避免不相应的情况!我仍然是Delphi novoice
我的问题是如何使这个功能多线程,以避免不相应的情况!我仍然是Delphi novoice
- procedure TfrMain.FileSearch(const PathName,FileName : string; txtToSearch : string; const InDir : boolean);
- var Rec : TSearchRec;
- Path : string;
- txt : string;
- fh : TextFile;
- i : integer;
- begin
- Path := IncludeTrailingBackslash(PathName);
- if FindFirst(Path + FileName,faAnyFile - faDirectory,Rec) = 0 then
- try
- repeat
- AssignFile(fh,Path + Rec.Name);
- Reset(fh);
- Readln(fh,txt);
- if ContainsStr(txt,txtToSearch) then
- ListBox1.Items.Add(Path + Rec.Name);
- until FindNext(Rec) <> 0;
- finally
- FindClose(Rec);
- end;
- If not InDir then Exit;
- if FindFirst(Path + '*.*',faDirectory,Rec) = 0 then
- try
- repeat
- if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name<>'.') and (Rec.Name<>'..') then
- FileSearch(Path + Rec.Name,FileName,txtToSearch,True);
- until FindNext(Rec) <> 0;
- finally
- FindClose(Rec);
- end;
- end;