search - Delphi - threads and FindFirst function -


I am facing a major problem when I am trying to create a recursive search function inside a thread ( By using Delphi 7) Bellow code is:

  TParcFicDir = class (TThread) private multiple variables .. Perform secure process; Override; Create Public Builders (CreateSuspended: Boolean); Manufacturer TParcFicDir.Create (CreateSuspended: Boolean); Create Heritage (CreateSuspended); End; TParcFicDir.Execute Process; FindFiles (FStartDir, FMask); // 'c: \' and '*. * E 'Except E': END Exception; End; Process TParcFicDir.FindFiles (StartDir, FileMask: string); Var wTmp: string; F: textfile; WTempSR: TSearchRec; Function Search (StartDear, File Mask: String): String; Var SR: TSearchRec; Isfound: boolean; Files: Integer; Dias: integer; T: string; Start trying files: = 0; Daras: = 0; If StartDir [Length (StartDir)] & lt; & Gt; '\' Then start: = StartDir + '\'; Try IsFound: = (FindFirst (StartDir + '*. *', FaAnyFile, SR) = 0); // gets interrupted except to leave the thread here: Exception ended; Whereas IsFound starts (SR.Name <> '.' ') And (SR.Name <>' .. ') then if ((SR.Attr and faDirectory) << ; 0) Then if FScanDirs then launches (DIRS); T: = Search (StartDir + SR.Name, FileMask); Try files: = files + strutton (copy (t), 0, position ('#', t) - 1)); // Old code, do not take on calculation; Delete (T, 1, Status ('#', T)); Dioras: = Dyers + Stront (T); Except E: Exception ends; Getting Started: = StartDir + SR.Name; WTmp: t =; Wtmp: = ''; Inc. (FDirNo); Writeln (f, t); Inc. (filno); End; On the other hand if scan files start (fino); Inc (files); End; Iffand: = Complex (SR) = 0; End; Results: = IntToStr (files) + '#' + IntToStr (DIRS); Sysutils.FindClose (SR); Except E: Exception ends; End; Start filno: = 0; Try Trim (FPathFileTmp) & lt; & Gt; '' Then AssignFile (f, FPathFileTmp + 'Temp.bak') and AssignFile (f, ExtractFileDir (GetDllName) + '\ temp.bak'); (F) rewrite; Search (StartDir, FileMask); If StartDir [Length (StartDir)] = '\' then Delete (StartDir, Length (StartDir), 1); WTmp: = StartDir; WTmp: = ''; If FindFirst (StartDir, faDirectory, wTempSR) = 0 then writeln (f); Writeln (f); CloseFile (f); Except E: Exception ends; Finally the end; End; Ok, maybe the code is a bit messy, but I do not know why the thread ends up on the 'searchfirst' part .... I went away, no results.  

Any help would be appreciated!

Thank you in advance

In your post code, I think that you are exception You have broken the code in which something happens, so first I leave the block and leave blank. Obstacles do not know what's going on because you throw away the information you need to remove.

There are two calls in the FindFirst () one in your code where one is trying to find the directory is suspicious. I will change your code in such a way.

  var SR: TSearchRec; Get started if FindFirst ('C: \', faDirectory, SR) & lt; & Gt; 0 Then RaiseLastOSError; End;  

Then you will see FindFirst () unsuccessful

in this case instead of using FindFirst () , Where you search the directory, I will use the DirectoryExists () call instead.


Comments