我制作了一个将数据从 A TClientDataSet 复制到 B 的函数。
在生产环境中,代码会动态填充一个 TClientDataSet,如下所示:
procedure LoadClientDataSet(const StringSql: String; ParamsAsArray: array of Variant; CdsToLoad: TClientDataSet);
begin
//There is a shared TClientDataSet that retrieves
//all data from a TRemoteDataModule in here.
//the following variables (and code) are here only to demonstration of the algorithm;
GlobalMainThreadVariable.SharedClientDataSet.CommandText := StringSql;
//Handle Parameters
GlobalMainThreadVariable.SharedClientDataSet.Open;
CdsToLoad.Data:= GlobalMainThreadVariable.SharedClientDataSet.Data;
GlobalMainThreadVariable.SharedClientDataSet.Close;
end;
那说:
- 这样做安全吗?(我的意思是安全的,我应该期待什么样的异常以及如何处理它们?)
- 如何释放“.Data”的内存?