View Issue Details

IDProjectCategoryView StatusLast Update
0033520FPCDocumentationpublic2018-03-27 14:27
ReporterHandokoAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinuxOSUbuntu Mate 64-bitOS Version17.10
Product VersionProduct Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033520: FindFirst example incorrect
DescriptionThe 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:

1) "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.

2) Wrong location of "Inc(Count);"
That line should be put inside the "If (Attr ..." condition.
Additional InformationProgram 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.
TagsNo tags attached.
Fixed in Revision1476
FPCOldBugId
FPCTarget
Attached Files

Activities

Michael Van Canneyt

2018-03-27 14:27

administrator   ~0107436

Fixed. The location of Inc(count) is correct. The count is the number of found items, not the number of found directories.

Issue History

Date Modified Username Field Change
2018-03-27 14:16 Handoko New Issue
2018-03-27 14:23 Michael Van Canneyt Project Lazarus => FPC
2018-03-27 14:23 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-03-27 14:23 Michael Van Canneyt Status new => assigned
2018-03-27 14:27 Michael Van Canneyt Fixed in Revision => 1476
2018-03-27 14:27 Michael Van Canneyt Note Added: 0107436
2018-03-27 14:27 Michael Van Canneyt Status assigned => resolved
2018-03-27 14:27 Michael Van Canneyt Fixed in Version => 3.1.1
2018-03-27 14:27 Michael Van Canneyt Resolution open => fixed
2018-03-27 14:27 Michael Van Canneyt Target Version => 3.2.0