delphiwinapishellfile-iodelphi-7

Delphi notification when a file gets updated


My app contains documents in its database. The users can open the documents in which case, the document gets saved to a temporary folder and gets opened on the user's computer.

I'd like to get a notification when one of these temporary files are changed, and offer the user to save the changed document back to the database.

What is the most simple way to do this in Delphi7? (I suppose it requires some shell magic or 3rd party component)

Thanks!


Solution

  • You can either:

    1. use the Win32 API SHChangeNotifyRegister function to watch for changes in the temp folder, and then have your callback check if your temporary files are reporting changes.

    2. since you know the exact file(s) you are interested in, you can manually monitor them directly for changes to their sizes and timestamps using FindFirstFile in a timer or thread.