|Subject:||Re: Sending records with Indy 10 : Problem with String|
|Posted by:||Remy Lebeau (Indy Team) (email@example.com)|
|Date:||Mon, 6 Nov 2006|
"Christian rodriguez" <cdrodrigu…@ambimetrics.com> wrote in message
> In Indy 10 I have the following code:
You cannot send records that contain AnsiString values (or any other
dynamically-allocated type). String values have to be sent individually.
> then, when I try to access de name field there is a access violation
As it should be. You are not taking the AnsiString's dynamic nature into
account at all. An AnsiString is actually just a pointer to a separate
memory block that holds the actual characters. While sending the record the
way you are, you are sending the pointer value itself, not the characters
that are being pointed to. The reader then ends up receiving a pointer
value that is outside of its valid address space. That is why it gets the
In order to send a record that contains strings, you have to send the
strings separately. That way, the actual characters are sent, not the
pointer that is pointing to them. For example:
--- Sender ---
with AContext.Connection.IOHandler do
--- Receiver ---
with AContext.CanalComandos.IOHandler do
dest.num := ReadInteger;
dest.num2 := ReadInteger;
dest.name := ReadString(ReadInteger);
> If I use a record without a string field the transmission is successful.
As it should be, because the record no longer contains dynamically allocated
data, so there is no errors in sending the data.
> I´m having also problems sending and receiving Objects, is
> there any consideration to take into account???
You can't send objects at all. You would have to copy their data into a
formatted buffer or stream, and then send/receive that instead.
Sending records with Indy 10 : Problem with String posted by Christian rodriguez on Sat, 4 Nov 2006