FireDAC 学习 - 2

复制数据

ClientDataSet 依赖的是 Midas.dll,也就是说它是在 Midas 框架里面的。

要想把一个 ClientDataSet 的数据复制给另外一个 ClientDataSet,最简单的做法是:ClientDataSet2.Data := ClientDataSet1.Data;

这里的 Data 是一个 Variant 变量,它内含了具体的数据。

但是,一个普通的 DataSet 比如一个 TADOQuery 是没有 Data 这个属性的。它的数据要变为 ClientDataSet 可以接收的数据,需要通过 TDataSetProvider 来完成。这是 Midas 框架下的操作。

----------------------

在 FireDAC 下面,上一篇文章说了一个 FDQuery 可以将数据输出为 TMemory,然后让 FdMemTable.LoadFromMem获得。

其实这里有一个更简单的方法:

FdMemTable1.Data := FdQuery1.Data;  //测试通过。

这里,Data 是一个接口 IFDDataSetReference。

Delphi 官方 Help 如此描述:

Represents the data of the dataset, allowing to fully copy data from one dataset into another.

The Data property represents the dataset's internal in-memory data storage. Using this property, an application can copy the current structure and data of one FireDAC dataset to another FireDAC dataset. 

The property value is a reference to the IFDDataSet interface. It is reference-counted and the application does not need to explicitly free it. If the application keeps the interface reference using a variable or a field, then the reference must be released before the dataset is closed. 

The dataset must be inactive to set this property value, otherwise an exception is raised. After its setting, the Self dataset:

  • Has a structure of an original dataset, excluding Indexes, IndexDefs, Filter, and so on.
  • Has a copy of an original dataset data, including all row versions and states (inserted, deleted, updated, unchanged).
  • Has CachedUpdates equal to True, if an original dataset has unapplied changes.
  • Is open.

Example

FDQuery1.SQL.Text := 'select * from orders; select * from customers';

FDQuery1.Open;
FDQuery1.FetchAll;
// assign orders records to FDMemTable1
FDMemTable1.Data := FDQuery1.Data;

FDQuery1.NextRecordSet;
FDQuery1.FetchAll;
// assign customers records to FDMemTable2
FDMemTable2.Data := FDQuery1.Data;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值