首页 > 代码库 > firedac数据集的序列和还原

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;

firedac数据集的序列和还原