I guess Martin locked this issue. Only admins and moderators can reply. My profile says "Moderator" but I cannot lock or unlock threads. I see a "Split topic" button but it does not help. I don't know what this "Moderator" status is good for.
Martin, can you please unlock. It is OK to criticize a function here.
[Edit] OK, Martin didn't lock it. I guess technical discussion about FindAllFiles, if needed, must go to a new thread.
That is not the way of creating object in Pascal and sign of lack of understanding basic concepts.
AFAIK there is no strict rule that an object must be created and freed in the same function. You just must pay attention and remember to free it.
The only strict rule is to free it somewhere.
The same idea is used in many Codetools functions and elsewhere. Sometimes extra var parameters pass optional new lists or other objects. You can Free such an object even if the function didn't create it (Free a Nil reference is OK).
That being said, such code looks out of balance. True! I also prefer to first create and then pass an object.
Fortunately FindAllFiles has an overload version for that. Please use it.
Bart and Juha? Now I understand all...
FindAllFiles was originally meant to be a simple utility function. Then all kinds of corner cases turned out. Extra parameters had to be added. Now there is a struggle with symlinks AFAIK.
The function does not look simple and nice any more.
Solution: Instead of function FindAllFiles use the underlying class TFileSearcher. It provides methods and events to analyze the found files and directories. A TStringList is not needed.
TFileSearcher was originally hidden under implementation section. It was moved to interface section due to user requests.