Thanks, Nigel, BUT.....it send integers fine, but I am having problems
getting it to pass the data in the pointer.
It is populated when it leaves the client port, but when it come sin the
server app's port, it is blank. As I say, the integer is passed ok...it
MIGHT be the way I am receiving it....I am doing :-
Sockets1.SReceive(Socket,@TestRec,len);
memo1.lines.add(inttostr(TestRec.iMyInt));
memo1.lines.add(strpas(TestRec.sMyCString));
Any Ideas ??
Thanks, Jeremy Coulter
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Nigel Tavendale
> Sent: Wednesday, April 14, 1999 16:47
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Passing record structures
>
>
> This may be an alterative. Use a structure like so:
>
> type
> PMyRec = ^MyRec;
> MyRec = packed record
> iMyInt : Integer;
> sMyCString : Pointer;
> end;
>
> The problem seems to be passing strings. Instead of that use a
> pointer in a
> packed record (packed will use single byte alignment you can try
> it using an
> ordinary record as well).
>
> Then you use something like:
>
> procedure TForm.PassMyRecord(InputInt:Integer;InputS:String);
> var
> aTest : Array [0..MAX_PATH] of Char;
> begin
> //Convert String To Array of Char
> StrPCopy(aTest,InputS);
>
> //populate record
> TestRec.iMyInt:=InputInt;
> TestRec.sMyCString:=@aTest;
>
> //Pass record into API call
> APICall(@TestRec,SizeOf(TestRec));
> end;
>
> I usually try with or without packing the record. Usually One will work.
>
> Nigel.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Dennis Chuah
> Sent: Wednesday, 14 April 1999 10:47
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Passing record structures
>
>
>
> 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
>
>
> ------------------------------------------------------------------
> ---------
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz