View Issue Details

IDProjectCategoryView StatusLast Update
0038091LazarusLCLpublic2021-01-11 09:57
ReporterdevEric69 Assigned ToJuha Manninen  
Status resolvedResolutionfixed 
Summary0038091: Request for modification of FileUtil.pas (TListFileSearcher.DoFileFound and TListDirectoriesSearcher.DoDirectoryFound)
DescriptionWell, when TListFileSearcher.DoFileFound or TListDirectoriesSearcher.DoDirectoryFound "matches", I \ we know that the current field named FileName that has passed the filtering of the search mask (glob regex of the FileName), and the filtering of the possible attributes of the file (hidden or not, system or not, ...). The field named FileName is therefore a file or a directory that interests me \ us, and that I \ we add to the FList. But, I find that the event associated with each correspondence (a file or a directory), missed to be pulled to take advantage of the inheritance. So, I propose to add 2 lines (Cf. // ++):

procedure TListFileSearcher.DoFileFound;
  inherited DoFileFound; // ++

procedure TListDirectoriesSearcher.DoDirectoryFound;
  inherited DoDirectoryFound; // ++

TagsNo tags attached.
Fixed in Revisionr64355
Attached Files



2020-11-17 11:51

developer   ~0126997

I think it is more logical when the "inherited" is called AFTER the *List.Add calls because then the new entry is already listed when the event fires -- an event handler, for example, counting the found items on the fly would see the correct number of entries this way.


2020-11-17 14:06

reporter   ~0126998

Indeed, the event can rather be read as "found" the list, TListFileSearcher or TListDirectoriesSearcher (therefore, already stored inside the list).


2021-01-08 12:30

reporter   ~0128167

Hello, Here is the tiny patch that should be applied so that the 2 classes keep the launch of their inherited specialised events, if they are coded.
fileutil_inc.patch (456 bytes)   
--- /tmp/rabbitvcs-7a9f1ac9e5/
+++ /home/cheetah/lazarus/components/lazutils/
@@ -617,6 +617,7 @@
 procedure TListFileSearcher.DoFileFound;
+  inherited DoFileFound;
 constructor TListFileSearcher.Create(AList: TStrings);
@@ -657,6 +658,7 @@
 procedure TListDirectoriesSearcher.DoDirectoryFound;
+  inherited DoDirectoryFound;

fileutil_inc.patch (456 bytes)   

Serge Anvarov

2021-01-08 17:22

reporter   ~0128171

Enough "inherited" in case the methods are renamed.

Juha Manninen

2021-01-08 17:38

developer   ~0128172

Looks valid to me, too. Applied with plain "inherited". Please test.


2021-01-11 09:57

reporter   ~0128260

Works as expected, on my computer at least:
procedure TForm1.Button1Click(Sender: TObject);
  sDirParentDirToVisit, sSearchMask: string;
  bSearchSubDir: boolean;
  oSL: TStringList;
  oSearcher: TListDirectoriesSearcher;
  i: integer;
    sDirParentDirToVisit:= '/home/Sheta/Test';
    sSearchMask:= '*'; // all
    bSearchSubDir:= True;
    oSL:= TStringList.Create;
    oSearcher:= TListDirectoriesSearcher.Create(oSL);
    oSearcher.OnDirectoryFound:= @OnDirectoryFound; // plugs inherited OnDirectoryFound
    oSearcher.Search(sSearchPath, sSearchMask, bSearchSubDirs); // 1°) Calling - here - inherited TFileSearcher.Search...
    for i:= Pred(oSL.Count) downto 0 do begin
      ShowMessage('Internal dir. stored');
    FreeAndNil(oSL); FreeAndNil(oSearcher);

procedure TForm1.OnDirectoryToRemoveFromStagingDir(DirectoryIterator: TFileIterator);
// 2°) TFileSearcher.Search does the "job" (is it a directory, or is it a file?); if it finds that it's a directory, then it calls DoDirectoryFound...
// 3°) ... then TListDirectoriesSearcher.FDirectoriesList.Add(FileName) is called. TListDirectoriesSearcher is specialized to store only dirs.
// 4°) ... then, inherited is called. Polymorphism and inheritance works, because it comes there:
  ShowMessage('Event: Dir. found!');

Issue History

Date Modified Username Field Change
2020-11-17 10:35 devEric69 New Issue
2020-11-17 11:07 Michael Van Canneyt Project FPC => Lazarus
2020-11-17 11:51 wp Note Added: 0126997
2020-11-17 14:06 devEric69 Note Added: 0126998
2021-01-08 12:30 devEric69 Note Added: 0128167
2021-01-08 12:30 devEric69 File Added: fileutil_inc.patch
2021-01-08 17:22 Serge Anvarov Note Added: 0128171
2021-01-08 17:30 Juha Manninen Assigned To => Juha Manninen
2021-01-08 17:30 Juha Manninen Status new => assigned
2021-01-08 17:38 Juha Manninen Status assigned => resolved
2021-01-08 17:38 Juha Manninen Resolution open => fixed
2021-01-08 17:38 Juha Manninen Fixed in Revision => r64355
2021-01-08 17:38 Juha Manninen LazTarget => -
2021-01-08 17:38 Juha Manninen Note Added: 0128172
2021-01-11 09:57 devEric69 Note Added: 0128260