@ASerge
1-2 years a go a forum user(cannot recall his name) asked for a tool which can compare two folders/drives. He was only interested in files, this is why sub-directories are ignored. I did it in 30 minutes or so, no wonder contains bugs.
1. Why do we need a variable FDone?
2. May be property NeedToBreak is superfluous, because already there is Terminated?
Usually when one or more thread needs to be terminated immediately, for example application close, users prefers the following method(especially if they come from delphi/windows background):
//...
Thread.Terminate;
Thread.WaitFor;
//...
In my experience this works well on windows, however it will cause dead lock in other os like linux/osx. I prefer the following:
a. Set FreeOnTerminate to true right after you create the thread
b. In the execute method, use a while loop and do some task in smalls chunks
c. When the thread needs to be terminated, set a boolean value to true(NeedToBreak for example), then immediately exit the while loop/Execute method, and the thread will take his natural course. This way you can run a lot of threads without external SIGSEGV, memory leaks/ dead locks, etc...
FDone with FNeedToBreak is indeed redundant and we can get rid of FDone. More over in this particular case the while loop is also not necessary. I do not understand why I put there in the first place.
3. Why do you first search only for names, then only for directories? In Window, this will be a double search. True the OS caches well and re-searches many times faster.
You're right, but I doubt your method will be much faster.