Delphi XE2 Datasnap 回调

发布于 2024-12-21 08:27:02 字数 519 浏览 1 评论 0原文

我正在尝试进行回调,发送不同的对象类型和对象的一些额外信息。所以我创建了这个类:

  TCallBackObject = class
    Sender : string;
    ObjectClass : string;
    Obj : TObject;
    Status : integer;
    ID : integer;
  end;

在不同的情况下,我在 Obj 字段中创建不同的对象,但在执行 DSServer.BroadcastObject 时总是收到错误消息“Internal: Cannot instantiate object ...”

这是我非常简单的示例: http://www.4shared.com/file/fONlAGM3/DataSnapExample.html

请查看示例并告诉我出了什么问题...

I am trying to make a callback, sending different object types and some extra info for the objects. So I made this class:

  TCallBackObject = class
    Sender : string;
    ObjectClass : string;
    Obj : TObject;
    Status : integer;
    ID : integer;
  end;

In different situations I create different Objects in the Obj field, but I always get the error message when executing DSServer.BroadcastObject "Internal: Cannot instantiate object ..."

Here is my really simple example: http://www.4shared.com/file/fONlAGM3/DataSnapExample.html

Please see the example and tell me what is wrong...

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

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

发布评论

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

评论(1

人│生佛魔见 2024-12-28 08:27:02

在客户端,对象类不在可执行文件中。
可以肯定的是,尝试一下这张脏支票。在客户端代码中创建引用所使用的类的引用。
例如。

TForm6 = class(TForm)
  SQLConnection1: TSQLConnection;
  DSClientCallbackChannelManager1: TDSClientCallbackChannelManager;
  Button1: TButton;
  Label1: TLabel;
  Label2: TLabel;
  procedure Button1Click(Sender: TObject);
  procedure OnExecute(AValue: TObject);
private
  c: TCat; //dummy refernce to the class
  d: TDog;  //dummy refernce to the class
  co: TCAllbackObject; //dummy refernce to the class
public
  { Public declarations }
end;

现在应该可以了。

一种更简洁的方法是为每个类使用一个空的寄存器类方法。如下:

  TCallBackObject = class
    Sender: string;
    ObjectClass: string;
    Obj: TObject;
    Status: integer;
    ID: integer;
    class procedure Register;
  end;
  ...
  class procedure TCallBackObject.Register;
  begin
    //
  end;

  initialization

    TCallBackObject.Register;

end.

On the client side, the objects classes are not in the executable.
To be sure, try this dirty check. Create a reference in the client code referring to the used classes.
eg.

TForm6 = class(TForm)
  SQLConnection1: TSQLConnection;
  DSClientCallbackChannelManager1: TDSClientCallbackChannelManager;
  Button1: TButton;
  Label1: TLabel;
  Label2: TLabel;
  procedure Button1Click(Sender: TObject);
  procedure OnExecute(AValue: TObject);
private
  c: TCat; //dummy refernce to the class
  d: TDog;  //dummy refernce to the class
  co: TCAllbackObject; //dummy refernce to the class
public
  { Public declarations }
end;

Now it should works.

A cleaner way is to use an empty register class method for each classes. As the following:

  TCallBackObject = class
    Sender: string;
    ObjectClass: string;
    Obj: TObject;
    Status: integer;
    ID: integer;
    class procedure Register;
  end;
  ...
  class procedure TCallBackObject.Register;
  begin
    //
  end;

  initialization

    TCallBackObject.Register;

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