Re: How to read/write records in Indy 10

Giganews Newsgroups
Subject: Re: How to read/write records in Indy 10
Posted by:  Remy Lebeau (Indy Team) (no.spam@no.spam.com)
Date: Mon, 21 Aug 2006

"Grant Brown" <gra…@sitedoc.com.au> wrote in message
news:6CDAED62B604E340gra…@sitedoc.com.au...

> In Indy 9 I could do :-
>
> IdTCPClient.ReadBuffer(TransRecord,SizeOf(TransRecord),true);

There is no third parameter in Indy 9's ReadBuffer() method.

> But how do I do this in Indy 10.

You have to use ReadBytes() to fill in a TIdBytes, and then use BytesToRaw()
to copy the TIdBytes into your record, ie:

    var
        Buf: TIdBytes;
        TransRecord : MyRecord;

    IdTCPClient.IOHandler.ReadBytes(Buf, SizeOf(TransRecord));
    BytesToRaw(Buf, TransRecord, SizeOf(TransRecord));

> How do I send the record from the TCP Server component

Use RawToBytes() to copy the record into a TIdBytes, and then use the
Write(TIdBytes) method.

    var
        Buf: TIdBytes;
        TransRecord : MyRecord;

    Buf := RawToBytes(TransRecord, SizeOf(TransRecord));
    AContext.Connection.IOHandler.Write(Buf);

Gambit

Replies

In response to

How to read/write records in Indy 10 posted by Grant Brown on Sun, 20 Aug 2006