FindFirst example incorrect
Original Reporter info from Mantis: Handoko
-
Reporter name: Handoko
Original Reporter info from Mantis: Handoko
- Reporter name: Handoko
Description:
The example in the FindFirst documentation is incorrect:
https://www.freepascal.org/docs-html/rtl/sysutils/findfirst.html
The example does not give correct result tested on my Linux computer. I found there were 2 mistakes in the example:
-
"and faDirectory" is not needed
Incorrect:
If FindFirst ('*',faAnyFile and faDirectory,Info)=0 then
Correct:
If FindFirst ('*',faAnyFile,Info)=0 then
Reason:
The parameter Attr is an or-ed combination, faAnyFile already includes faDirectory.
-
Wrong location of "Inc(Count);"
That line should be put inside the "If (Attr ..." condition.
Additional information:
Program Example43;
{ This program demonstrates the FindFirst function }
Uses SysUtils;
Var Info : TSearchRec;
Count : Longint;
Begin
Count:=0;
If FindFirst ('*',faAnyFile and faDirectory,Info)=0 then
begin
Repeat
Inc(Count);
With Info do
begin
If (Attr and faDirectory) = faDirectory then
Write('Dir : ');
Writeln (Name:40,Size:15);
end;
Until FindNext(info)<>0;
end;
FindClose(Info);
Writeln ('Finished search. Found ',Count,' matches');
End.
Mantis conversion info:
- Mantis ID: 33520
- OS: Ubuntu Mate 64-bit
- OS Build: 17.10
- Platform: Linux
- Version: 1.8
- Fixed in version: 3.1.1
- Fixed in revision: 1476 (#1cde45ea)
- Target version: 3.2.0