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

Reply via email to