Delphi 7 remobjects - 序列化组件

发布于 2024-10-18 22:53:15 字数 1352 浏览 3 评论 0原文

我有一个用 Delphi 7 和 RemObjects SDK 构建的客户端-服务器应用程序。客户端和服务器之间的消息是二进制的(http://wiki.remobjects.com/wiki/BinMessage )。我的问题是: 1)如果我填充数据TDataSet/TDataSource并将它们从客户端发送到服务器,服务器组件的DataSet将包含数据?数据应该保持持久不是吗? 2)我尝试通过 RemObjects 发送组件,封装在 TROBinaryMemoryStream 后代类中,但如果没有成功

发送数据源的类定义

  TRODataSource=class(TROBinaryMemoryStream)
   private
     FNameDS:String;
     FDS:TDataSource;
     procedure SetName(aValue:String);
     procedure SetDS(aValue:TDataSource);
  public
   published
    property Name:String read FNameDS write SetName;
    property DataSource:TDataSource read FDS write SetDS;
  end;

方法,

function foo(aDataSource: TDataSource):integer;
var
  wStream:TRODataSource;
begin
 wStream:=TRODataSource.Create;
 wStream.Name:='TEST';
 wStream.DataSource:=aDataSource;
 try
  Result:=(RORemoteService as ISvc..).foo1(wstream);//method existing on the server will //return how many records are in the dataset
 finally
  freeandnil(wstream);
 end;
end;

任何答案都会受到赞赏。

LE:似乎只有 TROComplexType 的后代类可以被序列化 http://wiki.remobjects.com/wiki /Remote_Object_Allocation_and_Serialization。但我不确定是否无法序列化流上的组件。

I have a client-server application built in Delphi 7 and RemObjects SDK. Messages between client and server are binary (http://wiki.remobjects.com/wiki/BinMessage). My questions are:
1) if I fill with data a TDataSet/TDataSource and sent them from client to server, on the server component's DataSet will contain the data? the data should remain persistent no?
2) I've tried to send the component through RemObjects, encapsulated in a TROBinaryMemoryStream descendant class, but without succes

class definition

  TRODataSource=class(TROBinaryMemoryStream)
   private
     FNameDS:String;
     FDS:TDataSource;
     procedure SetName(aValue:String);
     procedure SetDS(aValue:TDataSource);
  public
   published
    property Name:String read FNameDS write SetName;
    property DataSource:TDataSource read FDS write SetDS;
  end;

method which send the datasource

function foo(aDataSource: TDataSource):integer;
var
  wStream:TRODataSource;
begin
 wStream:=TRODataSource.Create;
 wStream.Name:='TEST';
 wStream.DataSource:=aDataSource;
 try
  Result:=(RORemoteService as ISvc..).foo1(wstream);//method existing on the server will //return how many records are in the dataset
 finally
  freeandnil(wstream);
 end;
end;

any answer will be apreciated.

LE: it seems that only classes descendants of the TROComplexType can be serialized http://wiki.remobjects.com/wiki/Remote_Object_Allocation_and_Serialization. But I'm not sure if I can not serialize a component on a stream.

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

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

发布评论

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

评论(2

橙味迷妹 2024-10-25 22:53:15

当您将组件序列化为流时(请参阅我的另一篇文章),您可以使用“Binary”类型将流从服务器发送到客户端(以及反向):
http://wiki.remobjects.com/wiki/TROBinaryMemoryStream_Class

或者只是将其作为字符串发送: -)。无需覆盖 TROBinaryMemoryStream!

When you have your component serialized to a stream (see my other post), you can use the "Binary" type to send the stream from the server to client (and reverse):
http://wiki.remobjects.com/wiki/TROBinaryMemoryStream_Class

Or just send it as a string :-). No need to override TROBinaryMemoryStream!

桜花祭 2024-10-25 22:53:15

对于 TComponent/TPersistent 序列化(就像 Delphi 对 .dfm 文件所做的那样),您可以使用“ObjectTextToBinary”:
http://docs. embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Classes_ObjectTextToBinary@[电子邮件保护编辑]

但是,如果您使用子对象(对象属性),这会产生问题。

您还可以搜索更通用的序列化(使用 RTTI)到 XML 等:
Delphi (win32) 序列化库
Delphi组件序列化

编辑:您可以将结果作为RemObjects中的字符串发送或将其放入TMemoryStream中使用 RO 二进制类型。

For TComponent/TPersistent serialization (like Delphi does with .dfm files), you can use "ObjectTextToBinary":
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Classes_ObjectTextToBinary@[email protected]

However, this gives problems if you use sub objects (object properties).

You can also search for more general serialization (using RTTI) to XML etc:
Delphi (win32) serialization libraries
Delphi Component Serialization

Edit: you can send the result as a string in RemObjects or put it in a TMemoryStream and use the RO Binary type.

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