Search code examples
delphiserializationdelphi-xedatasnappodo

DataSnap "Plain Old Delphi Objects" and nested objects


A new article about DataSnap in Delphi XE explains that DataSnap now is able to transfer TObject-descendants between server and client, similar to the Java Enterprise Edition concept of POJO's ("Plain old Java objects").

Does this new feature work if such a PODO has a nested object-type properties which needs to be initialized, for example a TStrings property? Will all of these sub-objects be serialized and transferred with their current values? What about system resource properties, like TFileStream, THandle or TThread, which would make no sense in a serialized object, can these be tagged as 'not serializable'?


Some information is in the DocWiki, including this:

These are the fields for which there is already a built-in conversion/reversion: integer, string, char, enumeration, float, object, record. For the following types, the field values are ignored and user conversion is expected: set, method, variant, interface, pointer, dynArray, classRef, array.


Solution

  • I haven't tried myself but reading the documentation it appears it will serialize just about anything although you may need to write a custom convertor. The following code which contains sub-objects is given as an example of an object requiring a custom convertor.

    type
      TAddress = record
        FStreet: String;
        FCity: String;
        FCode: String;
        FCountry: String;
        FDescription: TStringList;
      end;
    
      TPerson = class
      private
        FName: string;
        FHeight: integer;
        FAddress: TAddress;
        FSex: char;
        FRetired: boolean;
        FChildren: array of TPerson;
        FNumbers: set of 1..10;
      public
        constructor Create;
        destructor Destroy; override;
    
        procedure AddChild(kid: TPerson);
      end;