码迷,mamicode.com
首页 > Web开发 > 详细

FIREDAC的TFDJSONDataSets和TFDJSONDeltas

时间:2014-10-07 01:39:12      阅读:1711      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   os   ar   for   数据   sp   art   

一)服务器端代码演示
1)常量定义:
const sDepartment = ‘Department‘; sEmployees = ‘Employees‘;

2)查询数据:

function TServerMethods1.GetDepartmentEmployees(const AID: string): TFDJSONDataSets;
begin
  // Clear active so that query will reexecute.
  FDQueryDepartmentEmployees.Active := False;
  FDQueryDepartment.Active := False;
  FDQueryDepartment.Params[0].Value := AID;
  FDQueryDepartmentEmployees.Params[0].Value := AID;
 
   // Create dataset list
  Result := TFDJSONDataSets.Create;
   // Add departments dataset
  TFDJSONDataSetsWriter.ListAdd(Result, sDepartment, FDQueryDepartment);
    // Add employees dataset
  TFDJSONDataSetsWriter.ListAdd(Result, sEmployees, FDQueryDepartmentEmployees);
end;
TFDJSONDataSets,FIREDAC的数据集列表对象,可返回多个数据集。

3)提交数据:
procedure TServerMethods1.ApplyChangesDepartmentEmployees(
  const ADeltaList: TFDJSONDeltas);
var
  LApply: IFDJSONDeltasApplyUpdates;
begin
  // Create the apply object
  LApply := TFDJSONDeltasApplyUpdates.Create(ADeltaList);
  // Apply the department delta
  LApply.ApplyUpdates(sDepartment, FDQueryDepartment.Command);
  if LApply.Errors.Count = 0 then
    // If no errors, apply the employee delta
    LApply.ApplyUpdates(sEmployees, FDQueryDepartmentEmployees.Command);
  if LApply.Errors.Count > 0 then
    // Raise an exception if any errors.
    raise Exception.Create(LApply.Errors.Strings.Text);
end;

二)客户端演示代码
1)查询数据:
procedure TForm2.GetDepartmentEmployees(const ADEPTNO: string);
var
    LDataSetList: TFDJSONDataSets;
    LDataSet: TFDDataSet;
begin
    LDataSetList := ClientModule1.ServerMethods1Client.GetDepartmentEmployees(ADEPTNO);
    // Get department dataset
    LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSetList,sDepartment);
    // Update UI
    FDMemTableDepartment.Active := False;
    FDMemTableDepartment.AppendData(LDataSet);
 
    // Get employees dataset
    LDataSet := TFDJSONDataSetsReader.GetListValueByName(LDataSetList, sEmployees);
    // Update UI
    FDMemTableEmployee.Active  := False;
    FDMemTableEmployee.AppendData(LDataSet);
end;
2)提交数据:
function TForm2.GetDeltas: TFDJSONDeltas;
begin
  // Post if editing
  if FDMemTableDepartment.State in dsEditModes then
  begin
    FDMemTableDepartment.Post;
  end;
 
  if FDMemTableEmployee.State in dsEditModes then
  begin
    FDMemTableEmployee.Post;
  end;
 
  // Create a delta list
  Result := TFDJSONDeltas.Create;
  // Add deltas
  TFDJSONDeltasWriter.ListAdd(Result, sEmployees, FDMemTableEmployee);
  TFDJSONDeltasWriter.ListAdd(Result, sDepartment, FDMemTableDepartment);
end;


procedure TForm2.ApplyUpdates;
var
  LDeltaList: TFDJSONDeltas;
begin
  LDeltaList := GetDeltas;
 
  // Call server method.  Pass the delta list.
  ClientModule1.ServerMethods1Client.ApplyChangesDepartmentEmployees(LDeltaList);
 
end;

注意:
服务端和客户端都要放置2个控件:
TFDStanStorageJSONLink
 TFDStanStorageBinLink


 
 

FIREDAC的TFDJSONDataSets和TFDJSONDeltas

标签:des   http   io   os   ar   for   数据   sp   art   

原文地址:http://www.cnblogs.com/hnxxcxg/p/4008789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!