// // 主函数,此函数由应用程序员编写... function MainFunction(RequestParcel: TQBParcel; ResponseParcel: TQBParcel): boolean; var InputJson,OutputJson: TQBJson; tmpstr: ansistring; begin // // 读取传入的Json... if RequestParcel.GoodsExists('_Request_Body') then begin tmpstr:=RequestParcel.GetAnsiStringGoods('_Request_Body'); try InputJson:=TQBJson.Create(tmpstr); except InputJson:=nil; end; end else InputJson:=nil;
// // 这里进行业务逻辑处理...
// // 生成REST输出... OutputJson:=TQBJson.Create; if InputJson=nil then begin OutputJson.Put('errcode',255); OutputJson.Put('errtext','传入的Json参数不存在或格式错!'); end else begin OutputJson.Put('errcode',0); OutputJson.Put('errtext','成功!'); OutputJson.Put('InputJson',InputJson); end; // // 返回Json、不进行GZIP压缩... ResponseParcel.PutAnsiStringGoods('ResponseBody',OutputJson.ToString3(3,3)); ResponseParcel.PutBooleanGoods('DisableGZip',true); result:=true; end;
// // 导出函数(应用程序员不用改)... function WebpageProcess(InParcelPtr: integer; var OutParcelPtr: integer): boolean; stdcall; var aInParcel: TQBParcel; aOutParcel: TQBParcel; begin try aInParcel:=TQBParcel(InParcelPtr); except result:=false; exit; end; aOutParcel:=TQBParcel.Create; Result:=MainFunction(aInParcel,aOutParcel); if aOutParcel.GoodsCount<=0 then OutParcelPtr:=0 else OutParcelPtr:=Parcel2Mem(aOutParcel); aOutParcel.free; end;
procedure TForm1.Button2Click(Sender: TObject); begin if mbconn.connect then memo1.lines.add('连接成功,请继续测试!') else memo1.lines.add('连接失败,无法继续测试!'); end;
procedure TForm1.Button3Click(Sender: TObject); var InJson,OutJson: TMBJson; begin InJson:=TMBJson.create; InJson.put('Name','李晓明'); InJson.put('Age',35); if Rpc.JsonCall('/restdemo.asq',InJson,OutJson) then begin memo1.lines.add('调用成功!OutputJson:'); memo1.lines.add(OutJson.ToString3(3,3)); end else memo1.lines.add('调用失败!LastError='+Rpc.lasterror); InJson.free; if assigned(OutJson) then FreeAndNil(OutJson); end;
procedure TForm1.Image1Click(Sender: TObject); begin close; end;