Serialized Adodataset, Adoquery (reprint)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.