Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Copying records or arrays using tcp/ip

www.cryer.info
Managed Newsgroup Archive

Re: Copying records or arrays using tcp/ip

Subject:Re: Copying records or arrays using tcp/ip
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Fri, 11 Jan 2008 09:51:53

"D-Fan" <D-Fan@antispam.com> wrote in message
news:478705a4$1@newsgroups.borland.com...

> Based on the example provided by Craig what is the
> best way to construct this in Indy 10?

Since Craig's record contains no dynamic data in it, you can simply use
RawToBytes() to convert the entire record instance into a TIdBytes and then
call the Connection object's IOHandler.Write(TIdBytes) method to send it,
and the ReadBytes() method with BytesToRaw() to receive it on the other end,
ie:

    --- client ---

    var
        Order: TOrderInfo;
        Buf: TIdBytes;
    begin
        // fill Order as needed...
        Buf := RawToBytes(Order, SizeOf(Order));
        IdTCPClient1.IOHandler.Write(Buf);
    end;


    --- server ---

    var
        Buf: TIdBytes;
        Order: TOrderInfo;
    begin
        AContext.Connection.IOHandler.ReadBytes(Buf, SizeOf(Order));
        BytesToRaw(Buf, Order, SizeOf(Order));
        // use Order as needed...
    end;

If the record contained dynamic data in it instead (String, dynamic array,
Variant, etc), then you would have to send/read the individual record
members one at a time instead.


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive