0

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.

RBA
  • 12,337
  • 16
  • 79
  • 126
  • Instead serializing the TDataSet it might be much easier to serialize the plain data. – mjn Feb 23 '11 at 14:29
  • yes, I know. I've tried to serialize a datasource/dataset to build some kind of a framework, but it seems that is harder than I've expected. – RBA Feb 24 '11 at 13:58

2 Answers2

1

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@TStream@TStream.html

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.

Community
  • 1
  • 1
André
  • 8,920
  • 1
  • 24
  • 24
  • thanks Andre, I've seen this example, and RRUIZ's code is excelent. But I need to send this through RemObjects (project demand).+1 – RBA Feb 23 '11 at 10:53
1

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!

André
  • 8,920
  • 1
  • 24
  • 24
  • yes, I've already done it. but now the problem is, that I must register the class, so Delphi knows it, to keep the data(because of the WriteComponent). If I'm sending a DataSource, I receive on the server an object with DataSet property nil...I'll try to sent it as string. thank you. – RBA Feb 23 '11 at 12:31
  • yes, both client and server must know what kind of object you send. In case of default Delphi TComponent serialization you must use "RegisterClass" so TComponent can deserialize it. This is also needed when you send it as a string – André Feb 23 '11 at 12:44
  • you did something like this? unit ... initialization RegisterClass(MyScrollBar); (see demo of Delphi wiki article) – André Feb 23 '11 at 13:58