Firedac:如何使用数据集 reader / writer 设置 TFDBatchMove?

Firedac: How to set up TFDBatchMove with data set reader / writer?

我正在尝试使用 reader 和编写器数据集设置一个名为 FDBatchMoveTFDBatchMove 对象。根据 this documentation

An application should assign the required reader and writer to the properties, and then call the Execute method.

根据 documentation 对于 TFDBatchMoveDataSetReader 应该

Use TFDBatchMoveDataSetReader to define the source dataset from which to load information using TFDBatchMove.

Set the DataSet property to select the dataset.

Choose the TFDBatchMoveDataSetReader as the Reader property of the TFDBatchMove.

TFDBatchMoveDataSetWriterdocumentation 包含相同的步骤。

因此,我创建了一个 TFDBatchMoveDataSetReader 和一个 TFDBatchMoveDataSetWriter 对象,并像这样设置它们的数据集值:

TFDBatchMoveDataSetReader * Reader = new TFDBatchMoveDataSetReader( this );
Reader->DataSet = MyDataSet1;

TFDBatchMoveDataSetReader * Writer = new TFDBatchMoveDataSetReader( this );
Writer->DataSet = MyDataSet2;

但是,当我尝试设置 TFDBatchMove 对象的 reader 和编写器 属性 时,我 运行 遇到了问题(即文档中的第三步).

代码...

FDBatchMove->Reader = Reader;
FDBatchMove->Writer = Writer;  

...给我以下错误:

E2034 Cannot convert 'TFDBatchMoveDataSetReader *' to '_di_IFDBatchMoveReader'

E2034 Cannot convert 'TFDBatchMoveDataSetWriter *' to '_di_IFDBatchMoveWriter'

我尝试明确创建一个新的 _di_IFDBatchMoveReader 对象,但是该对象不允许我访问数据集 属性。我应该如何使用数据集 reader 和数据集编写器设置我的 TFDBatchMove 对象?

看完这个 delphi example 我找到了解决办法。为了将 TFDBatchMoveDataSetReaderTFDBatchMoveDataSetWriter 对象应用于 TFDBatchMove 对象,您将 TFDBatchMove 对象作为所有者参数放在它们的构造函数中。所以在我的例子中,它看起来像这样:

TFDBatchMoveDataSetReader * Reader = new TFDBatchMoveDataSetReader( FDBatchMove );
TFDBatchMoveDataSetReader * Writer = new TFDBatchMoveDataSetReader( FDBatchMove );