DataSnap“普通旧 Delphi 对象”和嵌套对象

发布于 2024-10-27 04:22:11 字数 635 浏览 2 评论 0原文

一篇关于 Delphi XE 中 DataSnap 的新文章解释说 DataSnap 现在能够传输 TObject 后代服务器和客户端之间的交互,类似于 Java 企业版 POJO 的概念(“普通旧 Java 对象”)。

如果这样的 PODO 具有需要初始化的嵌套对象类型属性(例如 TStrings 属性),那么此新功能是否有效?所有这些子对象都会被序列化并以其当前值传输吗?系统资源属性(例如 TFileStream、THandle 或 TThread)在序列化对象中没有任何意义,可以将它们标记为“不可序列化”吗?


一些信息位于 DocWiki 中,包括:

这些是有的字段 已经是内置的 转换/恢复:整数、字符串、 字符、枚举、浮点数、对象、 记录。对于以下类型, 字段值被忽略并且用户 预期转换:集合、方法、 变体、接口、指针、dynArray、 类引用,数组。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-11-03 04:22:11

我自己还没有尝试过,但阅读了文档,它似乎会序列化几乎所有内容,尽管您可能需要编写一个自定义转换器。以下包含子对象的代码作为需要自定义转换器的对象的示例给出。

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文