Data set serialization function Recordsettoxml (const Recordset: _recordset): String;var rs:variant; Stream:tstringstream;begin Result: = "; If Recordset = nil then Exit; Stream: = Tstringstream.create ('); Try RS: = Recordset; ADPERSISTADTG saved as a binary file adPersistXML saved as XML. The binary transfer efficiency is higher than the XML RS. Save (Tstreamadapter.create (stream) as IUnknown, ADPERSISTADTG); Stream.position: = 0; Result: = stream.datastring; Finally Stream.free; End;end; Strxml: = Recordsettoxml (Fadoquery.recordset);//Compress the data, note the compression ratio do not select the highest iscompress: = Eclcompressandencryptstring (StrXML, Outstr, PassWord, CompressionLevel, false); If Iscompress then begin//formatted as 16 binary string Compressstr: = Strtoformat (PChar (OUTSTR), Length (OUTSTR), fmthex);//Tell to receive The length of the data to be sent AThread.Connection.WriteInteger (length (COMPRESSSTR)); Stream: = Tstringstream.create (COMPRESSSTR);//Send Data AThread.Connection.WriteStream (Stream, True); Stream.free; Restore DataSet function Recordsetfromxml (const xml:string): _reCordset;var rs:variant; Stream:tstringstream;begin Result: = nil; If XML = ' then Exit '; Try Stream: = Tstringstream.create (XML); Stream.position: = 0; RS: = Createoleobject (' ADODB. Recordset '); Rs. Open (Tstreamadapter.create (Stream) as IUnknown); Result: = IUnknown (RS) as _recordset; Finally Stream.free; End;end; Procedure Ttcpadoclient.open (value:string); var hexstr, decstr:string; Stream:tstringstream; Lenbuf:integer;begin Value: = uppercase (value); Fidtcpclient.writeln (' selectsql: ' + Value); Fcommand: = Value; Application.processmessages; If not fidtcpclient.connected then exit; Lenbuf: = Fidtcpclient.readinteger; Stream: = Tstringstream.create ('); try//Read Data Fidtcpclient.readstream (Stream, Lenbuf, False); Hexstr: = Formattostr (PChar (stream.datastring), Length (stream.datastring), fmthex);//Extract data Ecldecompressanddecryptstring (Hexstr, Decstr, PassWord); application.processmessages;//Restore DataSet Frecordset: = RecordsetfromxML (DECSTR); Finally Stream.free; End RecordSet: = Frecordset;end;
Serialization and restoration of Adodataset.recordset (reproduced)