Jeremy,
Hi. If you are already handling strings, you can use your existing code.
There are 2 options:
1. If you decide to use TComponent derived classes instead of records, you
can publish your data as properties, stream that into a TStringStream and
pass the string to your TCP/IP code. When you read from the socket, read it
into a TStringStream and stream it back into the component. This puts the
properties as binary code into the string.
Alternatively, you can stream the class into a memory stream
(TMemoryStream), call ObjectBinaryToText to convert the stream into a
string. This has the advantage that the data is in string format and should
help with debugging; but the disadvantage is the data size is then larger.
You will need to call ObjectTextToBinary when reading it out of the socket.
2. Copy the record into a string:
type
Tr = record
end;
var
r: Tr;
s: string;
begin
SetLength (s, sizeof (r));
Move (r, PChar(s)^, sizeof (r));
{ Then pass the string to your socket }
{ To read ... }
Move (PChar(s)^, r, sizeof(r));
Hope this helps.
Dennis.
> Yeah well, I am way ahead of you here Dennis.
> I have an app that it already communicating via TCP/IP fine, but it is
> passing strings....as it is a proto type.
> I now want to step it up a notch, and start getting some structure to the
> way things happen, and thought a record structure is one of the
> best ways of
> adding structure to data. (kind of)
>
> I am using strings in my records, but I guess I can change it to a PChar.
>
> so how do I treat it as a memory block ?
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz