Any gottcha on using TTimer for date monitoring and screen updates?

I want to determine when the file date changes and the DevX TdxMemData is updated, which is used as Tdatasource, which will then be displayed in the TDBGrid that uses it.

I found code that uses ReadDirectoryChangesW, but seems rather complicated for my simple needs.

I am considering using TTimer and firing from it every five seconds. (For me it's pretty good accuracy.)

Are there any reservations to this? I read that threads have all kinds of restrictions on access to VCL, etc. Does the same apply to TTimer events?

Is there anything I need to keep track of the FileAge call and the DevEx TdxMemData object updating during the Timer event? Will these updates be visible in my main application?

Is there a way to detect the “state” of my program when the Timer event gets control, so I can avoid problems?

Or am I opening a huge can of worms while thinking about using TTimer for this?

+3
source share
4 answers

The Demos directory has a component called "ShellChangeNotifier" that will trigger events when files are modified, added or deleted inside the directory. However, it has only one OnChange event, so you do not know what actually happened.

There is a discussion and solution to the problem at about.com

+5

TTimer , VCL. , , OnClick - , Application.ProcessMessages.

ReadDirectoryChangesW. , , , . , , , .

+8

Windows allows you to track file changes. For a start to the transition, see http://delphi.about.com/od/kbwinshell/l/aa030403a.htm . Several pre-made components are available. Google for “modifying a Delphi monitor file” or something similar

+4
source

You can check mine: DirectoryWatch

This is a wrapper around ReadDirectoryChangesW functions. This is more specific to changes than ShellChangeNotifier.

+1
source

Source: https://habr.com/ru/post/1735686/


All Articles