The server directly converts the data from the Tadoquery query directly to the Tstream itself for delivery to the client to restore the stream with a Tadoquery object.
Method One < reprint >
is to save the recordset as a stream interface, turn into Olevariant, write the inflow
class function Tadotools.savetostream2 ( pvdataset:tcustomadodataset): Tmemorystream;var astream:_stream; V:olevariant; P:pointer;begin astream:=costream.create; Olevariant (Pvdataset.recordset). Save (Astream, ADPERSISTADTG); astream.position:=0; V:=astream.read (astream.size); Result:=tmemorystream.create; Try p:=vararraylock (V); Try result. Size:=vararrayhighbound (v,1) +1; Move (P^,result. memory^, result. Size); Finally Vararrayunlock (V); End; Except result. Free (); Result: = nil; raise; End;end;
class procedure tadotools.loadfromstream2 (pvdataset:tcustomadodataset; Pvstream:tmemorystream); var v:olevariant; Ar:_recordset; Astream:_stream; P:pointer;begin pvstream.position:=0; Olevariant (Pvdataset.recordset). Open (Tstreamadapter.create (Pvstream) as IUnknown, ADPERSISTADTG); Ar. Open (Astream, emptyparam,adopenunspecified, adLockUnspecified,-1); Pvdataset.recordset:=adoint._recordset (AR); V:=vararraycreate ([0,pvstream.size-1], varbyte); P:=vararraylock (V); Try Move (pvstream.memory^, p^, pvstream.size); Finally Vararrayunlock (V); End Astream:=costream.create; Astream.open (Emptyparam,admodeunknown,adopenstreamunspecified, ","); Astream.type_:=adtypebinary; Astream.write (V); Ar:=_recordset (corecordset.create); astream.position:=0; Ar. Open (astream,emptyparam,adopenunspecified, adLockUnspecified,-1); Pvdataset.recordset:=adoint._recordset (AR); end;
Method Two: Directly call the Recordset to save the stream borrowing Tstreamadapter
Class procedure Tadotools.savetostream (Pvdataset:tcustomadodataset; pvstream:tstream); Begin Olevariant ( Pvdataset.recordset). Save (Tstreamadapter.create (Pvstream) as IUnknown, ADPERSISTADTG); Adpersistxmlend;class procedure Tadotools.loadfromstream (pvdataset:tcustomadodataset; Pvstream:tstream); var ar:_recordset;begin Ar:=_recordset (corecordset.create); pvstream.position:=0; Ar. Open (Tstreamadapter.create (Pvstream) as IUnknown, Emptyparam,adopenunspecified, adLockUnspecified,-1); Pvdataset.recordset:=adoint._recordset (AR); end;
Serialized Adodataset, Adoquery (reprint)