Delphi 7 remobjects - serialize a component

1.6k views Asked by At

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.

2

There are 2 answers

3
André On BEST ANSWER

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!

1
André On

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.