-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFileThread.pas
More file actions
70 lines (55 loc) · 1.3 KB
/
ReadFileThread.pas
File metadata and controls
70 lines (55 loc) · 1.3 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
62
63
64
65
66
67
68
69
70
unit ReadFileThread;
interface
uses
Classes, MMSystem, syncobjs;
type
TFileReaderThd = class(TThread)
private
{ Private declarations }
WaveFile: HMMIO;
Event: TEvent;
BytesToRead,
BytesRead: Integer;
Buffer: Pointer;
protected
procedure Execute; override;
public
constructor Create(AWaveFile: HMMIO);
destructor Destroy; override;
end;
implementation
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure FileReaderThd.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ FileReaderThd }
procedure TFileReaderThd.Execute;
var wr: TWaitResult;
begin
{ Place thread code here }
while not Terminated do
begin
wr := Event.WaitFor(60000);
if wr = wrSignaled then
begin
BytesRead := mmioRead(Wavefile, Buffer, BytesToRead);
end;
end;
end;
constructor TFileReaderThd.Create(AWaveFile: HMMIO);
begin
inherited Create(True);
WaveFile := AWaveFile;
Event := TEvent.Create(nil, False, False, '');
Resume;
end;
destructor TFileReaderThd.Destroy;
begin
Event.Free;
inherited;
end;
end.