View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038091 | Lazarus | LCL | public | 2020-11-17 10:35 | 2021-01-11 09:57 |
Reporter | devEric69 | Assigned To | Juha Manninen | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Summary | 0038091: Request for modification of FileUtil.pas (TListFileSearcher.DoFileFound and TListDirectoriesSearcher.DoDirectoryFound) | ||||
Description | Well, 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; begin inherited DoFileFound; // ++ FList.Add(FileName); end; procedure TListDirectoriesSearcher.DoDirectoryFound; begin inherited DoDirectoryFound; // ++ FDirectoriesList.Add(FileName); end; | ||||
Tags | No tags attached. | ||||
Fixed in Revision | r64355 | ||||
LazTarget | - | ||||
Widgetset | |||||
Attached Files |
|
|
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. |
|
Indeed, the event can rather be read as "found" ...in the list, TListFileSearcher or TListDirectoriesSearcher (therefore, already stored inside the list). |
|
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/rabbitvcs-1-base-fileutil.inc +++ /home/cheetah/lazarus/components/lazutils/fileutil.inc @@ -617,6 +617,7 @@ procedure TListFileSearcher.DoFileFound; begin FList.Add(FileName); + inherited DoFileFound; end; constructor TListFileSearcher.Create(AList: TStrings); @@ -657,6 +658,7 @@ procedure TListDirectoriesSearcher.DoDirectoryFound; begin FDirectoriesList.Add(FileName); + inherited DoDirectoryFound; end; |
|
Enough "inherited" in case the methods are renamed. |
|
Looks valid to me, too. Applied with plain "inherited". Please test. |
|
Works as expected, on my computer at least: [quote] procedure TForm1.Button1Click(Sender: TObject); var sDirParentDirToVisit, sSearchMask: string; bSearchSubDir: boolean; oSL: TStringList; oSearcher: TListDirectoriesSearcher; i: integer; begin 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'); end; FreeAndNil(oSL); FreeAndNil(oSearcher); end; 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: begin ShowMessage('Event: Dir. found!'); end; [/quote] |
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 |