DATASNAP远程方法返回TSTREAM正解

DATASNAP远程方法返回TSTREAM正解

DATASNAP远程方法返回TSTREAM,如果数据大小超过32K是会报错的。许多DELPHIER栽在这个上头,甚至开始怀疑TSTREAM返回数据的可行性。

因为DATASNAP远程方法返回TSTREAM,数据包大小有最大32K限制。

怎么解决?客户端要做并包处理。

function CopyStream(const AStream: TStream): TMemoryStream;
const
LBufSize = $F000;
var
LBuffer: TBytes;
LReadLen: Integer;
begin
Result := nil;
if AStream = nil then
Exit;
Result := TMemoryStream.Create;
try
if AStream.Size = -1 then
begin
SetLength(LBuffer, LBufSize);
repeat
LReadLen := AStream.Read(LBuffer[0], LBufSize);
if LReadLen > 0 then
Result.WriteBuffer(LBuffer[0], LReadLen);
if LReadLen < LBufSize then
break;
until LReadLen < LBufSize;
end
else
Result.CopyFrom(AStream, 0);
Result.Position := 0;
except
Result.Free;
end;
end;

 

procedure TForm1.btnQry3Click(Sender: TObject);
var
LStream: TStream;
LMemStream: TMemoryStream;
begin
DataSource1.DataSet := FDMemTable1;
LStream := methods.QuerySql3('0', 'select * from t1');
if LStream <> nil then
begin
LMemStream := CopyStream(LStream);
FDMemTable1.LoadFromStream(LMemStream, TFDStorageFormat.sfBinary);
LMemStream.Free;
end;
end;

posted @ 2017-11-02 07:14  delphi中间件  阅读(1436)  评论(0编辑  收藏  举报