1
votes

I would like to know how to send and receive an object as "TPerson" between two different applications.

It would be possible using DataSnap? Is there another way?

Thanks.

2
This link could be of interest: fmxexpress.com/… I haven't tried it out myself but the end result looks like you can pass objects back and forth using DataSnap. - Sentient
The serialization support in Delphi is poor and mainly in the Datasnap unit: docwiki.embarcadero.com/RADStudio/XE4/en/… . Otherwise as others have said you have to inspect the object yourself :-( , export/import it in JSON or another format and then initialize the object with those values on the other end. This library might help you though: code.google.com/p/delphi-oop/wiki/SvSerializer - alcalde

2 Answers

1
votes

Objects cannot be passed across process boundaries. They have to be serialized, such as with COM or JSON.

0
votes

An object instance is just a bunch of memory. Passing a dump of this memory from one application to another is a non sense, even if both applications are running on the same computer.

Instead, you can send the property values of the source object instance to the receiving application and apply the values to a local instance.

One easy way to do is to write a ToString() and a FromString() function to TPerson. Once you get a string from ToString, you can transmit it to the receiving application using any communication method (For example a TCP/IP socket, shared memory, email, FTP, HTTP or whatever fits your needs). The receiving application use FromString method to initialize the receiving object with the values embedded in the string.

ToString() and FromString() can be generically written by using RTTI. Or can simple be encode the old way in the class. JSON or XML libraries can help as well.