本文介绍了在Delphi XE6中使用Datasnap流式传输TClientDataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试使用Delphi XE6中的Datasnap流式传输TClientDataSet。但是,我一直在客户端代码上收到缺少数据提供者或数据包错误。

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.

//客户端

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;

//服务器

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;

我还尝试了将其作为XML而不是二进制流化

I also tried Streaming it as XML instead of Binary

  CDS.SaveToStream(result, dfXML);

得到相同的错误

丢失数据提供者或数据包

"Missing Data Provider or Data Packet"

ANSWER:

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


推荐答案

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

这篇关于在Delphi XE6中使用Datasnap流式传输TClientDataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 14:01