Streaming TClientDataSet using Datasnap in Delphi XE6

元气小坏坏 提交于 2019-12-24 01:22:15

问题


I am trying to stream a TClientDataSet using Datasnap in Delphi XE6. However, I keep getting a "Missing Data Provider or Data Packet" error on the client side code.

//Client

procedure TForm2.Button1Click(Sender: TObject);
var
 CDS: TClientDataSet;
 S: TStream;
begin
  CDS := TClientDataSet.Create(nil);
  try
    S:= ClientModule1.ServerMethods1Client.getCDSData;
    S.Seek(0,soFromBeginning);
    S.Position:= 0;
    CDS.LoadFromStream(S);
    CDS.Open; // Missing Data Provider or Data Packet
  finally
    CDS.Free;
  end;
end;

//Server

function TServerMethods1.getCDSData: TStream;
var
  Writer: TBinaryWriter;
  CDS: TClientDataSet;
  I: Integer;
begin
  result := TMemoryStream.Create;
  CDS := TClientDataSet.Create(nil);
  with CDS.FieldDefs do
  begin
    Clear;
    Add('First', ftString, 20);
    Add('Last', ftString, 25);
  end;
  CDS.CreateDataSet;
  CDS.Open;
  CDS.AppendRecord(['John', 'Smith']);
  CDS.AppendRecord(['Jane', 'Doe']);
  try
    CDS.SaveToStream(result);
  finally
    CDS.Free;
  end;
end;

I also tried Streaming it as XML instead of Binary

  CDS.SaveToStream(result, dfXML);

get the same error

"Missing Data Provider or Data Packet"

ANSWER:

CDS.SaveToStream(result);
Result.Position := 0; //need this in server method "getCDSData"

回答1:


CDS.SaveToStream(result);
Result.Position := 0; 


来源:https://stackoverflow.com/questions/37450199/streaming-tclientdataset-using-datasnap-in-delphi-xe6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!