delphi clientdataset Field 'amount' cannot be modified.
·
clientdataset 修改数据可能报错不让修改,如下:
Field 'amount' cannot be modified.
或
Trying to modify read-only field.
用下面的过程在clientdataset打开后 执行下,重新生成下clientdataset的字段属性即可,
procedure SetDstAllFieldCanEdit(dstNm: TClientDataSet; AddFields: string = '');
vartmpDst: TClientDataSet;
I: Integer;
begin
tmpDst := TClientDataSet.Create(nil);
try
dstNm.DisableControls;
tmpDst.Data := dstNm.Data;
dstNm.Close;
dstNm.FieldDefs.Clear;
for I := 0 to tmpDst.FieldDefs.Count - 1 do
begin
with dstNm.FieldDefs.AddFieldDef do
begin
DataType := tmpDst.FieldDefs[I].DataType;
Size := tmpDst.FieldDefs[I].Size;
Name := tmpDst.FieldDefs[I].Name;
end;
end;
// CreateAttachColumns(dstNm,AddFields);
dstNm.CreateDataSet;
with tmpDst do
begin
First;
while not Eof do
begin
dstNm.Append;
for I := 0 to Fields.Count - 1 do
dstNm.Fields[I].Value := Fields[I].Value;
Next;
end;
end;
if dstNm.State in [dsInsert, dsEdit] then
dstNm.Post;
dstNm.MergeChangeLog;
finally
dstNm.EnableControls;
tmpDst.Free;
end;
end;
更多推荐
所有评论(0)