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:"Craig" (firebirdwebg..@hotmail.com)
Date:Thu, 10 Jan 2008 09:36:15

Its really easy..

I send a record of data like..

type
  TOrderInfo = record
    RetCode: Integer;
    OrderNumber: Integer;
    OrdTot: Integer;
    OrderTimeStr: string[30];
    UserName: string[15];
    Pass: string[15];
end;

** Notice the fixed length strings..


I have a Var

Var MyOrder : TOrderInfo;

I then fill it with data..

To send it , I save it to a memorystream..


/// use this function to take your record and put it into a stream..
procedure WriteRecToStream(const Rec: TOrderInfo; Stream: TStream);
  begin
    Stream.WriteBuffer(Rec, SizeOf(Rec));
  end;


Now, I just send my memory stream over winsock..


On the other side.. Im reading data...

/// get the data from winsock..size of my record..
SocketIO.ReadToStream(WorkStream, Sizeof(TOrderInfo));
WorkStream.Seek(0, soFromBeginning); // position stream access

//Now convert my stream back to a record so we can use it..
ReadRecFromStream(MasterEAInfo, WorkStream);

// code to take stream and convert it back to a record..
procedure ReadRecFromStream(var Rec: TOrderInfo; Stream: TStream);
  begin
    Stream.ReadBuffer(Rec, SizeOf(Rec));
  end;


Hope this helps!


"D-Fan" <D-Fan@nospam.net> wrote in message
news:4785541c$1@newsgroups.borland.com...
>
> Is there a way to transfer records, arrays, or other structures over the
internet using tcp/ip?

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive