I use a worker thread to read data with TIdTCPClient
, as described in other articles. The thread gets the data with this command:
FClient.IOHandler.ReadBytes (FData,-1,False);
where FClient
is the TIdTCPClient
and FData
is TIdBytes
.
This is the reading thread's whole Execute()
method:
procedure TReadingThread.Execute;
begin
inherited;
if not assigned(FClient.IOHandler) then exit;
while not terminated do
begin
if FClient.IOHandler <> nil then
begin
try
FClient.IOHandler.ReadBytes (FData,-1,False);
Synchronize(DataReceived);
SetLength (FData,0);
except
end;
end;
end;
end;
If I do not use SetLength (FData,0)
then the next incoming data is appended to FData
. I have never read about it in other discussions.
I am using Delphi RAD Studio 10.3.
Is this known that FData
has to be set to 0, or am I doing something wrong?