| Class TDiscMonitorThread (unit DiscMon) |
=== DISC MONITORING THREAD =================================================== This thread will monitor a given directory and subdirectories (if required) for defined filtered changes. When a change occurs the OnChange event will be fired, if an invalid condition is found (eg non-existent path) then the OnInvalid event is fired. Each event is called via the Sychronize method and so are VCL thread safe. // The thread is created suspended, so after setting the required properties you must call the Resume method.
| Constructors |
constructor Create;| Functions |
destructor Destroy;
procedure Execute;
procedure Update;
procedure InformChange;
procedure InformInvalid;
procedure SetDirectory (const Value : string);
procedure SetFilters (Value : integer);
procedure SetSubTree (Value : boolean);| Properties |
property Directory : string
property Filters : integer
property SubTree : boolean| Events |
event OnChange : TNotifyEvent
event OnInvalid : TNotifyEvent| Variables |
FChangeEvent : THandle;
FDestroyEvent : THandle;
FDirectory : string;
FFilters : integer;
FOnChange : TNotifyEvent;
FOnInvalid : TNotifyEvent;
FSubTree : boolean;| Constructors |
constructor Create;=== MONITOR THREAD =========================================================== Create the thread suspended. Create two events, each are created using standard security, in the non-signalled state, with auto-reset and without names. The FDestroyEvent will be used to signal the thread that it is to close down. The FChangeEvent will be used to signal the thread when the monitoring conditions (directory, filters or sub-directory search) have changed. OnTerminate is left as false, so the user must Free the thread.
| Functions |
destructor Destroy;close OnXXXXX links, signal the thread that it is to close down
procedure Execute;The EXECUTE procedure ------- Execute needs to: 1. Call FindFirstChangeNotification and use the Handle in a WaitFor... to wait until the thread become signalled that a notification has occurred. The OnChange event is called and then the FindNextChangeNotification is the called and Execute loops back to the WaitFor 2. If an invalid handle is obtained from the above call, the the OnInvalid event is called and then Execute waits until valid conditions are set. 3. If a ChangeEvent is signalled then FindCloseChangeNotification is called, followed by a new FindFirstChangeNotification to use the altered conditions. 4. If a DestroyEvent is signalled then FindCloseChangeNotification is called and the two events are closed and the thread terminates. // In practice WaitForMultipleObjects is used to wait for any of the conditions to be signalled, and the returned value used to determine which event occurred.
procedure Update;On any of the above three changes, if the thread is running then signal it that a change has occurred.
procedure InformChange;called by the Execute procedure via Synchronize. So this is VCL thread safe
procedure InformInvalid;called by the Execute procedure via Synchronize. So this is VCL thread safe
procedure SetDirectory (const Value : string);Change the current directory
procedure SetFilters (Value : integer);Change the current filters
procedure SetSubTree (Value : boolean);Change the current sub-tree condition
| Properties |
property Directory : stringThe directory to monitor
property Filters : integerFilter condition, may be any of the FILE_NOTIFY_CHANGE_XXXXXXX constants ORed together. Zero is invalid.
property SubTree : booleanInclude subdirectories below specified directory.
| Events |
event OnChange : TNotifyEventEvent called when change noted in directory
event OnInvalid : TNotifyEventEvent called for invalid parameters
| Variables |
FChangeEvent : THandle;
FDestroyEvent : THandle;
FDirectory : string;
FFilters : integer;
FOnChange : TNotifyEvent;
FOnInvalid : TNotifyEvent;
FSubTree : boolean;