Skip to content

Commit eebaf33

Browse files
committed
[fileMonitor] bug fixed
1 parent 8c9eab8 commit eebaf33

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Quick.FileMonitor.pas

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ ***************************************************************************
22
3-
Copyright (c) 2015-2019 Kike Pérez
3+
Copyright (c) 2015-2021 Kike Pérez
44
55
Unit : Quick.FileMonitor
66
Description : Watch for single file changes
77
Author : Kike Pérez
88
Version : 1.2
99
Created : 11/09/2017
10-
Modified : 29/01/2019
10+
Modified : 10/05/2021
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -65,6 +65,7 @@ TFileMonitor = class(TThread)
6565
fModifedDate : TDateTime;
6666
fCurrentMonitorNotify : TMonitorNotify;
6767
fOnChangeNotify : TFileChangeNotify;
68+
fIsThreadStarted : Boolean;
6869
procedure SetEnabled(Status : Boolean);
6970
procedure NotifyEvent;
7071
protected
@@ -86,6 +87,8 @@ implementation
8687
constructor TFileMonitor.Create;
8788
begin
8889
inherited Create(True);
90+
fIsThreadStarted := False;
91+
fEnabled := False;
8992
Self.FreeOnTerminate := False;
9093
fInterval := 1000;
9194
fExists := False;
@@ -166,17 +169,23 @@ procedure TFileMonitor.Execute;
166169

167170
procedure TFileMonitor.SetEnabled(Status : Boolean);
168171
begin
169-
if (Status) and {$IFNDEF FPC}(not Started){$ELSE}(Suspended){$ENDIF} then Start;
170-
171172
if fEnabled <> Status then
172173
begin
173-
fEnabled := Status;
174-
//gets current values
175-
if TFile.Exists(fFileName) then
174+
if Status then
176175
begin
177-
fExists := True;
178-
fModifedDate := TFile.GetLastWriteTime(fFileName);
176+
//gets current values
177+
if TFile.Exists(fFileName) then
178+
begin
179+
fExists := True;
180+
fModifedDate := TFile.GetLastWriteTime(fFileName);
181+
end;
179182
end;
183+
if not fIsThreadStarted then
184+
begin
185+
fIsThreadStarted := True;
186+
if (Status) and {$IFNDEF FPC}(Started = False){$ELSE}(Suspended){$ENDIF} then Start;
187+
end;
188+
fEnabled := Status;
180189
end;
181190
end;
182191

0 commit comments

Comments
 (0)