Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Read data with TIdTCPClient

www.cryer.info
Managed Newsgroup Archive

Re: Read data with TIdTCPClient

Subject:Re: Read data with TIdTCPClient
Posted by:"Grant Brown" (gra..@sitedoc.com.au)
Date:21 Aug 2006 16:25:25

Hi Remy,

Thank you for the response (and others)

Could you explain the "= 204" part a bit further.

  if SendCmd(CmdStr_NewLic, [203, 204]) = 204 then

In your response the loop exits when the sendCmd() returns 204 but what
happens when it returns 203 which is in the list of valid responses.

In the above send command code the 203 and 204 equate to


203 = more records to come.
204 = this is the last record.

So how do I adjust the above line ?

TIA

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


--

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive