-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtwsyncthread.pas
More file actions
61 lines (50 loc) · 1.29 KB
/
Copy pathtwsyncthread.pas
File metadata and controls
61 lines (50 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
unit twSyncThread;
{$mode objfpc}{$H+}
interface
uses
twAutomate, Classes;
Type
TRefChangeEvent = procedure(Ref: String) of Object;
TTwSyncThread = class(TThread)
private
fCurrentRef : string;
FOnRefChange: TRefChangeEvent;
procedure RefChange;
protected
procedure Execute; override;
public
constructor Create(CreateSuspended : boolean);
property OnRefChange: TRefChangeEvent read FOnRefChange write FOnRefChange;
end;
implementation
constructor TTwSyncThread.Create(CreateSuspended : boolean);
begin
FreeOnTerminate := True;
twAutomate.TWAutomateUtils.Reset;
inherited Create(CreateSuspended);
end;
procedure TTwSyncThread.RefChange;
// this method is executed by the mainthread and can therefore access all GUI elements.
begin
if Assigned(FOnRefChange) then
FOnRefChange(fCurrentRef);
end;
procedure TTwSyncThread.Execute;
var
newRef: string;
begin
while not Terminated do
begin
newRef := twAutomate.TWAutomateUtils.GetTwCurrentRef();
if (newRef <> fCurrentRef) and (newRef <> '') then
begin
fCurrentRef := newRef;
Synchronize(@RefChange);
end;
if newRef = '' then
Sleep(5000) // try again in 5s in case of error
else
Sleep(500);
end;
end;
end.