TDataSet.InitFieldDefsFromfields Bug lazarus / 63-Database ---------------------------------------------------------------------- derek.john.evans · 2016-08-16 23:38 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 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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:=Field Defs.FieldDefClass.Create(FieldDefs,FieldName,DataType,Size,Required,F ieldDefs.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; ---------------------------------------------------------------------- LacaK · 2016-10-15 16:39 Edited: Although it seems strange, there is no bug  Because: FFieldDef:=FieldDefs.FieldDefClass.Create(FieldDefs,FieldName,DataType ,Size,Required,FieldDefs.Count+1); here are passed DataType and Required to newly created FFieldDef object, so after this statement FFieldDef and fields have same values for DataType and Required