F
flai
Unregistered / Unconfirmed
GUEST, unregistred user!
在如下的代码中,我希望由用户提供的FieldDefs列表动态地生成一个TClientDataSet
,在CreateDataset之前都是成功的,但是在为TClientDataSet增加计算字段时出错,
请问这是为什么,以及如何正确地增加计算字段?
谢谢!!
Type
TWIField=record
FldType:TFieldType;
Size:Integer;
FldName:String;
DisplayLabel:String;
Visible:boolean;
FldKind:TFieldKind;
end;
PWIField=^TWIField;
...............................
...............................
procedure CreateDataSet(CDSet:TClientDataSet;FieldDefs:TList);
Var
i:Integer;
AFld:TField;
begin
for i:=0 to FieldDefs.Count-1do
if PWIField(FieldDefs.Items).FldKind=fkData then
With CDSet.FieldDefs.AddFieldDefdo
begin
DataType:=PWIField(FieldDefs.Items).FldType;
if DataType=ftString then
Size:=PWIField(FieldDefs.Items).Size;
Name:=PWIField(FieldDefs.Items).FldName;
end;
if CDSet.FieldDefs.Count>0 then
CDSet.CreateDataSet;
///////////
if PWIField(FieldDefs.Items).FldKind=fkCalculated then
begin
AFld:=TField.Create(Application);
AFld.FieldKind:=fkCalculated;
AFld.FieldName:=PWIField(FieldDefs.Items).FldName;
if AFld.DataType=ftString then
AFld.Size:=PWIField(FieldDefs.Items).Size;
CDSet.Fields.Add(AFld);
end;
end;
,在CreateDataset之前都是成功的,但是在为TClientDataSet增加计算字段时出错,
请问这是为什么,以及如何正确地增加计算字段?
谢谢!!
Type
TWIField=record
FldType:TFieldType;
Size:Integer;
FldName:String;
DisplayLabel:String;
Visible:boolean;
FldKind:TFieldKind;
end;
PWIField=^TWIField;
...............................
...............................
procedure CreateDataSet(CDSet:TClientDataSet;FieldDefs:TList);
Var
i:Integer;
AFld:TField;
begin
for i:=0 to FieldDefs.Count-1do
if PWIField(FieldDefs.Items).FldKind=fkData then
With CDSet.FieldDefs.AddFieldDefdo
begin
DataType:=PWIField(FieldDefs.Items).FldType;
if DataType=ftString then
Size:=PWIField(FieldDefs.Items).Size;
Name:=PWIField(FieldDefs.Items).FldName;
end;
if CDSet.FieldDefs.Count>0 then
CDSet.CreateDataSet;
///////////
if PWIField(FieldDefs.Items).FldKind=fkCalculated then
begin
AFld:=TField.Create(Application);
AFld.FieldKind:=fkCalculated;
AFld.FieldName:=PWIField(FieldDefs.Items).FldName;
if AFld.DataType=ftString then
AFld.Size:=PWIField(FieldDefs.Items).Size;
CDSet.Fields.Add(AFld);
end;
end;