Datasnap remote methods support custom Object parameters

Source: Internet
Author: User

Colleagues need remote methods to transfer custom data types, he thought to write their own code will be very complex, in fact, Datasnap long ago for us to think of.

Datasnap's data sequences and restores are incredibly powerful, with remote methods that support custom object arguments, and Datasnap automatically use JSON sequences and restore custom objects.

1) Customizing an object

Type
Tmyinfo = Class (TObject)
Public
accountno:string;
sql:string;
params:string;
Recsmax:integer;
End

2) service-side remote method definition

function Tservermethods1.querysql4 (const myinfo:tmyinfo): Tfdjsondatasets;
Var
D:tfrmdb;
I, Ipos:integer;
Sl:tstringlist;
LName, LValue, lstr:string;
P:tfdparam;
Begin
Result: = nil;
If not Assigned (MyInfo) Then
Exit;
if (Myinfo.accountno = ") or (Myinfo.sql =") Then
Exit;
D: = Getdbpool (Myinfo.accountno). Lock;
If not Assigned (d) Then
Exit;
Try
Try
D.qryopen.close;
D.qryopen.sql.clear;
D.qryopen.sql.text: = Myinfo.sql;
If Myinfo.params <> ' then
Begin
SL: = Tstringlist.create;
Try
Sl. Delimiter: = '; ';
Sl. Delimitedtext: = Myinfo.params;
For I: = 0 to SL. Count-1 do
Begin
LSTR: = sl. Strings[i];
IPos: = Pos (': ', lstr);
LName: = Leftstr (Lstr, iPos-1);
LValue: = Rightstr (Lstr, Length (LSTR)-IPos);
P: = D.qryopen.findparam (LName);
If P <> Nil then
P.value: = LValue;
End
Finally
Sl. Free;
End
End
D.qryopen.open;
Result: = tfdjsondatasets.create;
Tfdjsondatasetswriter.listadd (Result, ' 1 ', d.qryopen);
Except
On E:exception do
Begin
Result: = nil;
Log.writelog (' tservermethods1.querysql2 ' + e.message);
End
End
Finally
D.qryopen.close;
Getdbpool (Myinfo.accountno). Unlock (d);
End
End

3) Client Calls

Procedure Tform1.button3click (Sender:tobject);
Var
Ldatasets:tfdjsondatasets;
Ldataset:tfddataset;
Myinfo:tmyinfo;
Begin
MyInfo: = tmyinfo.create;
Myinfo.accountno: = ' 0 ';
Myinfo.sql: = ' select * from t1 where c1=:c1 ';
Myinfo.params: = ' c1:55 ';
Ldatasets: = methods. QUERYSQL4 (MyInfo);
Ldataset: = Tfdjsondatasetsreader.getlistvaluebyname (Ldatasets, ' 1 ');
Fdmemtable1.close;
Fdmemtable1.data: = Ldataset;
End

Datasnap remote methods support custom Object parameters

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.