firedac数据集的序列和还原

procedure TForm1.Button1Click(Sender: TObject);
var
stream, stream2: TMemoryStream;
buf: TBytes;
begin

// 查询
FDQuery1.Close;
FDQuery1.SQL.Clear;
FDQuery1.Open('select * from t2');

// 序列为流

 

stream := TMemoryStream.Create;
FDQuery1.SaveToStream(stream, TFDStorageFormat.sfBinary);

// 流转换为BUFFER,将BUFFER通过网络分包传输

stream.Position := 0;
SetLength(buf, stream.Size);
stream.Read(buf[0], stream.Size);
stream.Free;

// BUFFER转换为流

stream2 := TMemoryStream.Create;
stream2.Write(buf[0], Length(buf));
stream2.Position := 0;

// 还原出数据

FDMemTable1.LoadFromStream(stream2, TFDStorageFormat.sfBinary);
stream2.Free;
end;

posted @ 2016-09-25 19:35  delphi中间件  阅读(829)  评论(0编辑  收藏  举报