Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Copying records or arrays using tcp/ip
| Subject: | Re: Copying records or arrays using tcp/ip |
| Posted by: | "D-Fan" (d-fan@antispam.com) |
| Date: | Thu, 10 Jan 2008 23:57:54 |
Thanks for the info, and filling in the sample.
Craig wrote:
> If you wanted to send a structure that you didnt know the length.. then you
> would need to send something preceding the array or record, telling the
> reciever how much data to expect.. Since mine is the same length every time.
> I dont..
>
> Also, you need to stay away from anything that has a pointer etc..you need
> to send fixed structures..Dynamic arrays would not work for instance..
>
>
> "Craig" <firebirdwebguy@hotmail.com> wrote in message
> news:47864951$1@newsgroups.borland.com...
>> 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?
none