无法将计算字段添加到clientdataset [英] Cannot add calculation field to clientdataset
问题描述
我正在尝试使用下面的代码向在 fieldDefs.add
创建的现有数据集中添加一个计算字段,并在包括堆栈溢出在内的多个站点上找到了许多变体。
I am trying to add a calculation field to an existing data set created with fieldDefs.add
using the code below with many variations I found on several sites including stack overflow.
但是 fieldDefs
行创建的 fieldDefs
dataSet
行中的 FieldDefs.count
丢失。
But the fieldDefs
created by the fieldDefs
line or by the dataSet
line are lost on update by FieldDefs.count
.
Fields.counts
保留,但不会保存到XML文件中。
Fields.counts
persist but are not saved to XML files.
没有引发异常。
有人知道这里发生了什么吗?
谢谢
Does anyone have any idea what is going on here? Thanks
MYclientDataSet.CreateDataSet;
MYclientDataSet.open;
MYclientDataSet.FieldDefs.Update;
MYclientDataSet.Active := False;
for i := 0 to MYclientDataSet.FieldDefs.Count - 1 do
MYclientDataSet.FieldDefs[i].CreateField(MYclientDataSet);
fld := TStringField.Create(MYclientDataSet);
with fld do begin
FieldName := 'PartSummary';
FieldKind := fkCalculated;
Calculated := True;
Name := cds.Name + FieldName;
DataSet := MYclientDataSet;
MYclientDataSet.FieldDefs.Add('PartSummary', ftString, 30, false);
MYclientDataSet.FieldDefs.update;
end;
MYclientDataSet.active := true;
MYclientDataSet.open;
MYclientDataSet.edit;
推荐答案
根据Delphi教育链接中的Cary Jensen 定义Clientdataset的结构... 您无法使用FieldDefs创建计算,查找,汇总字段。您必须改用TFields。
According to Cary Jensen in the Delphi education link Defining a Clientdataset's Structure... you cannot create a calculated, lookup, aggregate field using FieldDefs. You must use TFields instead.
这篇关于无法将计算字段添加到clientdataset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!