Just a post to see if this is a bug:
I came across what looks like a bug in TDataSet.InitFieldDefsFromfields (dataset.inc)
PROBLEM: TField and TFieldDef both have the properties Required & DataType.
The code is using two "with/do" statements (which needs to be fixed). The inner "with/do" is the TFieldDef (LINE:13), which refers to Required/DataType expecting to read from the outer TField (LINE:9). But, it just reads from itself.
Therefore, TField properties arn't copied to the TFieldDef's
procedure TDataSet.InitFieldDefsFromfields;
var i : integer;
begin
if FieldDefs.count = 0 then
begin
FieldDefs.BeginUpdate;
try
for i := 0 to Fields.Count-1 do with fields[i] do
if not (FieldKind in [fkCalculated,fkLookup]) then // Do not add fielddefs for calculated/lookup fields.
begin
FFieldDef:=FieldDefs.FieldDefClass.Create(FieldDefs,FieldName,DataType,Size,Required,FieldDefs.Count+1);
with FFieldDef do
begin
if Required then Attributes := attributes + [faRequired];
if ReadOnly then Attributes := attributes + [faReadOnly];
if DataType = ftBCD then precision := (fields[i] as TBCDField).Precision
else if DataType = ftFMTBcd then precision := (fields[i] as TFMTBCDField).Precision;
end;
end;
finally
FieldDefs.EndUpdate;
end;
end;
end;