问题描述
我在运行时为 TClientDataSet
创建 FieldDefs
。仍在运行时,我想删除所有 FieldDefs
。我将 TClientDataSet
物理保存到光盘文件中。我尝试使用以下代码删除现有的 FieldDefs
,以便添加新代码。但这没用:
I'm creating FieldDefs
at runtime for a TClientDataSet
. Still at runtime I want to remove all FieldDefs
. I'm saving TClientDataSet
physically to a disc file. I tried removing existing FieldDefs
using the following code so I could add new ones. But it didn't work:
with fDataSet do begin
Active := False;
DisableControls;
FieldDefs.Clear;
Fields.Clear;
EnableControls;
end;
执行此代码后, FieldDefs
和字段
的计数为 0
,但是如果我关闭并重新打开 disc文件
, FieldDefs
和 Fields
仍然存在。
After executing this code, FieldDefs
and Fields
count are 0
, but if I close and reopen the disc file
, FieldDefs
and Fields
are still there.
更改 FieldDefs
和 Fields
的正确方法是什么?
What is the right way to change FieldDefs
and Fields
?
推荐答案
连续Open从内部数据集重新创建字段。只需清除旧的字段定义,添加新的字段定义并重新创建数据集即可:
Consecutive Open recreates fields from internal Dataset. Just clear old field defs, add new ones and recreated dataset:
...
CDS.FieldDefs.Clear;
CDS.Fields.Add(...);
...
CDS.Fields.Add(...);
CDS.CreateDataSet;
...
这篇关于Delphi-具有数据的TClientDataSet的Change Fields定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!