问题
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.
回答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!
回答2:
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.
来源:https://stackoverflow.com/questions/5089037/delphi-7-remobjects-serialize-a-component