Delta and XML convert each other

Source: Internet
Author: User

We all know that the Delta attribute of tclientdataset stores changes in the dataset, but Delta is an olevariant attribute. If you use Delphi to write a WebService, You need to convert it into XML, especially when other languages use this WebService, the structure of the delta package is transparent if Delta can be converted to XML. However, tclientdataset does not provide deltaxml attributes. I searched online and found that Delta is assigned to the data of another tclientdataset, and then XML is returned through xmldata, however, it is difficult to create an object instance for a simple function. So I studied the source code of tclientdataset and finally completed the conversion between delta and XML,CodeAs follows:

 

Unit udelta;

Interface

Uses dbclient, dsintf, varutils, ActiveX;

Function deltatoxml (delta: olevariant): string;
Function xmltodelta (xmldata: string): olevariant;

Implementation

Procedure check (fdsbase: idsbase; Status: dbresult );
VaR
Errmsg: array [0 .. 2048] of char;
Begin
If status <> 0 then
Begin
Fdsbase. geterrorstring (status, errmsg );
Raise edbclient. Create (errmsg, status );
End;
End;

function deltatoxml (delta: olevariant): string;
var
fdsbase: idsbase;
datapacket: tdatapacket;
varpacket: olevariant;
begin
createdbclientobject (clsid_dsbase, idsbase, fdsbase);
safearraycheck (ActiveX. safearraycopy (vartodatapacket (DELTA), datapacket);
check (fdsbase, fdsbase. appenddata (datapacket, true);
fdsbase. setprop (dspropxml_streammode, xmlon);
check (fdsbase, fdsbase. streamds (datapacket);
datapackettovariant (datapacket, varpacket);
result: = variantarraytostring (varpacket);
// freedatapacket (datapacket );
end;

Function xmltodelta (xmldata: string): olevariant;
VaR delta: olevariant;
Datapacket: tdatapacket;
Fdsbase: idsbase;
Begin
Delta: = stringtovariantarray (xmldata );
Safearraycheck (safearraycopy (vartodatapacket (DELTA), datapacket ));
Createdbclientobject (clsid_dsbase, idsbase, fdsbase );
Check (fdsbase, fdsbase. appenddata (datapacket, true ));
Fdsbase. setprop (dspropxml_streammode, xmloff );
Check (fdsbase, fdsbase. streamds (datapacket ));
Datapackettovariant (datapacket, result );
// Freedatapacket (datapacket );
End;

End.

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.