Recent

Author Topic: TshellTreeView trick for others until they release the offical update for this.  (Read 3667 times)

jamie

  • Hero Member
  • *****
  • Posts: 7854
I've been using FindAllFiles recently because it saves a lot of time and with that I can populate a TTreeView.

 But at times I would like to filter out certain files and I can do that while I populate the TreeView, however, There also times where the list can get very large filled with files of no interest and that places a lag on the system.

 It would be a conceptional idea to have a version of the FindAllFiles with an optional CallBack that supplies access to the currently resolved string and allow for modification of the string or just simply reject it.

  That would also save some time.. here.
 ;D
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4217
It would be a conceptional idea to have a version of the FindAllFiles with an optional CallBack that supplies access to the currently resolved string and allow for modification of the string or just simply reject it.

That's easy, I did it to be able to show the search progress: FindAllfiles uses a TFileSearcher internally (which has events OnFileFound, OnDirectoryFound and OnDirectoryEnter) so you can use it to either build your own FindAllFiles() or directly in your app, forgeting about FindAllFiles() ;)

EDIT: Not "TSearcher" but "TFileSearcher"; sorry :-[
« Last Edit: April 18, 2020, 04:09:52 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 7854
Interesting, I'll have a look at the code but I wonder if the code as it is now is prepared to allow editing or removal of found entries upon those events ?

  I'll take a look at it , this could be a very sensible addition to the libs  :)
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Interesting, I'll have a look at the code but I wonder if the code as it is now is prepared to allow editing or removal of found entries upon those events ?

Not as it is; both FindAllFiles() and FindAllDirectories()) are relatively simple, no-frills, convenience functions. To do what you want you'll have to build your own versions but note that TFileSearcher events are rather simple by themselves (as couldn't be otherwise) and they just pass the TFileIterator to the handler.

What we did for another program was to subclass the searcher to add "confirmation" events and a "FindFiles" method which internally called the new events to know whether to add the files to the result list. That, though, may be overkill for you (it also extended the searcher in other ways): a simple unit implementing a "FindFiles" function with a callback parameter might be enough.

BTW, I initially wrote TSearcher, whereas the class name is TFileSearcher. Sorry about that; it's now corrected.
« Last Edit: April 18, 2020, 04:23:26 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 7854
YEs it's a simple function I can duplicate it with the added features and do an overload of it...

Just need to fully think about the all of the possibilities options in the event so that we don't need to keep making different versions, well that is, if others would like to use it too. For me it does not bother me to rebuild the single function for my own code, I just rebuild all projects that would use it  ::)
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018