Forum > Database

TDataSet.InitFieldDefsFromfields Bug

(1/1)

derek.john.evans:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;   

LacaK:
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

Navigation

[0] Message Index

Go to full version