Board index » delphi » Dynamic size records

Dynamic size records

Has anyone seen or got some code that shows how to send dynamic size records via a socket?

Static length records are fine such as :

type TUDPMsg = packed record
  FromPC  : array[0..49] of char;
  MsgType : array[0..19] of char;
  Msg     : array[0..1023] of char;
end;

But that is a very inefficient way of doing it and I want to send records that look like this :

type TUDPMsg = packed record
  FromPC  : array of char;
  MsgType : array of char;
  Msg     : array of char;
end;

Am I trying to do this the wrong way?
Must I use streams and how?

Thanks

 

Re:Dynamic size records


Look into using variants or a variant array of variants.

--
?+Catty_X1
msn : Catty...@Realitypoint.com
*Remember to Breathe*

Quote
"Paul Surgeon" <p...@lgrtelecoms.com> wrote in message

news:3c884290$1_1@dnews...

Has anyone seen or got some code that shows how to send dynamic size records
via a socket?

Static length records are fine such as :

type TUDPMsg = packed record
  FromPC  : array[0..49] of char;
  MsgType : array[0..19] of char;
  Msg     : array[0..1023] of char;
end;

But that is a very inefficient way of doing it and I want to send records
that look like this :

type TUDPMsg = packed record
  FromPC  : array of char;
  MsgType : array of char;
  Msg     : array of char;
end;

Am I trying to do this the wrong way?
Must I use streams and how?

Thanks

Re:Dynamic size records


Quote
> But that is a very inefficient way of doing it and I want to send records that look like this :

> type TUDPMsg = packed record
>   FromPC  : array of char;
>   MsgType : array of char;
>   Msg     : array of char;
> end;

Oftentimes, I will use descendants of TComponent for this.  If you
create a TComponent and add your three members as published properties,
you can then use the built in Component Streaming functions to send and
read the packets for you.

Look at TStream.ReadComponent, TStream.WriteComponent.

There are probably many examples of how to use this method, but if
you've got some old issues of "The Delphi Magazine" around, I wrote an
article on it quite some time ago.  You can probably search on their
website on my name to find the issue.

Their website: www.thedelphimagazine.com

Jason Southwell
Arcana Technologies Incorporated

Other Threads