Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Read data with TIdTCPClient
| Subject: | Re: Read data with TIdTCPClient |
| Posted by: | "Grant Brown" (gra..@sitedoc.com.au) |
| Date: | 21 Aug 2006 17:14:14 |
Hi Remy,
Which unit in Indy 10 contains RemoveBytes because when I try to
compile my code I get a compiler error with
[Pascal Error] SD4LChk.pas(193): E2003 Undeclared identifier:
'RemoveBytes'
IOHandler.InputBuffer.RemoveBytes(SizeOf(NewLicRec));
Kind Regards
Grant Brown
Remy Lebeau (TeamB) wrote:
>
> "Grant Brown" <grant@sitedoc.com.au> wrote in message
> news:44e98205@newsgroups.borland.com...
>
> > Is the following the correct manner in which to read records
> > using the TIdTCPClient component in Indy 10.
>
> No. You are calling ReadBytes(), which fills a TIdBytes. But you are
> specifying SizeOf(ByteBuf) where you need to use SizeOf(NewLicRec))
> instead. You can't call SizeOf() on a TIdBytes, it will alyways
> report the wrong value.
>
> > Also how would I gard against a lost connection during the repeat
> > loop
>
> The reading will throw an exception that you are not catching yet, so
> the loop will automatically exit when the connection is lost.
>
> Try this code instead:
>
> SetLength(ByteBuf, 0);
> with IdTCPClient do
> try
> repeat
> if SendCmd(CmdStr_NewLic, [203, 204]) = 204 then
> begin
> IOHandler.ReadBytes(ByteBuf, SizeOf(NewLicRec));
> BytesToRaw(ByteBuf, NewLicRec, SizeOf(NewLicRec));
> Break;
> end else begin
> IOHandler.InputBuffer.RemoveBytes(SizeOf(NewLicRec));
> end;
> until False;
> except
> on E: Exception do ShowMessage(E.Message);
> end;
>
>
> Gambit
--