View Issue Details

IDProjectCategoryView StatusLast Update
0034805FPCDocumentationpublic2019-01-04 14:48
ReporterMark Morgan LloydAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformAnyOSOS Version
Product Version3.0.4Product Build 
Target Version3.2.0Fixed in Version3.3.1 
Summary0034805: Example code for FindFirst()
DescriptionEither the call to FindClose() should be moved up by a line, or the spurious begin/end should be removed.
Additional Informationhttps://www.freepascal.org/docs-html/current/rtl/sysutils/findfirst.html
TagsNo tags attached.
Fixed in Revision1532
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0032012 resolvedMichael Van Canneyt Findfirst/findclose: if findfirst fails with error on handle, findclose should not be called. 

Activities

Thaddy de Koning

2019-01-03 15:48

reporter   ~0113129

Maybe like so:
{$mode objfpc}
Uses SysUtils;

Var Info : TSearchRec;
    Count : Longint = 0;
begin
  If FindFirst ('*',faAnyFile and faDirectory,Info) = 0 then
  try
    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;
  finally
    FindClose(Info);
    Writeln ('Finished search. Found ',Count,' matches');
  end;
end.

Mark Morgan Lloyd

2019-01-03 17:16

reporter   ~0113132

Last edited: 2019-01-03 17:18

View 2 revisions

Maybe. However I'd suggest that it's probably best to have as few syntactic features in an example as possible, and while it would be desirable to use try-finally-end, :nn to format output and so on they muddy the water for somebody who is still working through elementary language structure.

For various reasons I've been spending a bit of time in some very old ALGOL manuals, which really do emphasise the extent to which early technical writers hadn't worked out how to document a language: as a particular example, no distinction is made between the language syntax and (what we'd call) standard library facilities.

IMO, the industry owes a big debt to Kathleen Jensen who in one slim volume showed people how it should be done.

Michael Van Canneyt

2019-01-04 09:44

administrator   ~0113145

I simply moved the findclose.
I didn't add try/finally as this particular code normally does not require it.

Mark Morgan Lloyd

2019-01-04 14:48

reporter   ~0113156

TFT.

Issue History

Date Modified Username Field Change
2019-01-03 14:32 Mark Morgan Lloyd New Issue
2019-01-03 14:32 Mark Morgan Lloyd Status new => assigned
2019-01-03 14:32 Mark Morgan Lloyd Assigned To => Michael Van Canneyt
2019-01-03 15:48 Thaddy de Koning Note Added: 0113129
2019-01-03 17:16 Mark Morgan Lloyd Note Added: 0113132
2019-01-03 17:18 Mark Morgan Lloyd Note Edited: 0113132 View Revisions
2019-01-04 02:27 Marco van de Voort Relationship added related to 0032012
2019-01-04 09:44 Michael Van Canneyt Fixed in Revision => 1532
2019-01-04 09:44 Michael Van Canneyt Note Added: 0113145
2019-01-04 09:44 Michael Van Canneyt Status assigned => resolved
2019-01-04 09:44 Michael Van Canneyt Fixed in Version => 3.3.1
2019-01-04 09:44 Michael Van Canneyt Resolution open => fixed
2019-01-04 09:44 Michael Van Canneyt Target Version => 3.2.0
2019-01-04 14:48 Mark Morgan Lloyd Note Added: 0113156
2019-01-04 14:48 Mark Morgan Lloyd Status resolved => closed