4

Should I look at shell notifications? Is there a good free component, or some example source code?

Or should I just start a one second timer and check the file's timestamp periodically?

It doesn't have to be elegant, just the simplest that will work. I am more interested in the processing which I will do when the file changes (it's a log file, whenever it gets updated I want to parse it and show some details of the test run).

Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
  • 2
    Er, the simplest that works is polling. But it's also most least elegant. – David Heffernan Oct 17 '12 at 10:49
  • 1
    @David he anyway would be kinda polling. AFAIR Windows can not report about the details of changes, all it does is telling "rescan that folder, there was something changed in it". But he can poll on event rather than on timer. – Arioch 'The Oct 17 '12 at 14:04
  • 2
    @Arioch'The Not sure about folders, but Windows can report detailed changes on a single file, which is what is asked here. – GolezTrol Oct 17 '12 at 14:40
  • @DavidHeffernan 1 I don't care about elephants, so long as it works - simply – Mawg says reinstate Monica Oct 18 '12 at 05:53
  • @Golelz - i see, thanks. Turns out, XP introduced new API to be on part with Linux :-) Older Windows did not provided details info, that is even not in MSDN examples: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365261.aspx – Arioch 'The Oct 18 '12 at 06:34

2 Answers2

4

Shell notifications are nice, but more complex than a timer. If a one second polling interval is good enough, you could use that.

But you can build a 'Monitor' yourself, which encapsulates the actual monitoring code. This Monitor raises an event if the file is changed. That monitor of yours can encapsulate a timer at first (easy, two minute job), but can be modified to use shell notifications later (better), without having to modify all your application logic.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • +1 and the answer. In the end, I decided to KISS and went with a one second timer and Embarcadero's method of getting the file's timestamp (http://edn.embarcadero.com/article/15541). – Mawg says reinstate Monica Oct 18 '12 at 00:45
3

Jedi VCL inherits change-notification/folder-monitor from RxLib.
RxLib also might be available for older versions of Delphi

BTW, you did not specify you Delphi version. Please, press RETAG link and add the proper tag.

Arioch 'The
  • 15,799
  • 35
  • 62
  • +1 Thanks, I will look into that. I still don't use Jedi, but see so much mention of it that I think that I ought to. XE2 start, btw. – Mawg says reinstate Monica Oct 18 '12 at 00:44
  • 2
    thanks for mentioneing your version, but please, *press RETAG link and add the proper tag.* Your version is to be seen by search engine and by new readers. There are ttags - please use them. – Arioch 'The Oct 18 '12 at 06:13
  • yes, i know, but i hope for newcomers to *learn* local habits earliest when possible :-) – Arioch 'The Oct 19 '12 at 08:18