Got this pretty straight forward function to search for files:
function FindFiles(const Path, Mask: string; IncludeSubDir: boolean): integer;
var
FindResult: integer;
SearchRec: TSearchRec;
begin
Result := 0;
FindResult := FindFirst(Path + Mask, faAnyFile - faDirectory, SearchRec);
while FindResult = 0 do
begin
//!!!!!!!! This must synchronize Form1.Memo2.Lines.Add(Path + SearchRec.Name);
Result := Result + 1;
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
if not IncludeSubDir then
Exit;
FindResult := FindFirst(Path + '*.*', faDirectory, SearchRec);
while FindResult = 0 do
begin
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
Result := Result + FindFiles(Path + SearchRec.Name + '\', Mask, True);
FindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
It is called with :
FindFiles('C:\','*.*',TRUE)
How to break this into Delphi thread?
This code suits my needs (d2010) I just need to put it (or parts of it) into a thread.
Thanks
Maybe something like this?
If you want the items to be added to the VCL control one-by-one you lose some of the benefits of threading, but sure, it can be done: