Recent

Author Topic: TDataSet.InitFieldDefsFromfields Bug  (Read 3725 times)

derek.john.evans

  • Guest
TDataSet.InitFieldDefsFromfields Bug
« on: August 17, 2016, 01:38:18 am »
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][+][-]
  1. procedure TDataSet.InitFieldDefsFromfields;
  2. var i : integer;
  3.  
  4. begin
  5.   if FieldDefs.count = 0 then
  6.     begin
  7.     FieldDefs.BeginUpdate;
  8.     try
  9.       for i := 0 to Fields.Count-1 do with fields[i] do
  10.         if not (FieldKind in [fkCalculated,fkLookup]) then // Do not add fielddefs for calculated/lookup fields.
  11.           begin
  12.           FFieldDef:=FieldDefs.FieldDefClass.Create(FieldDefs,FieldName,DataType,Size,Required,FieldDefs.Count+1);
  13.           with FFieldDef do
  14.             begin
  15.             if Required then Attributes := attributes + [faRequired];
  16.             if ReadOnly then Attributes := attributes + [faReadOnly];
  17.             if DataType = ftBCD then precision := (fields[i] as TBCDField).Precision
  18.             else if DataType = ftFMTBcd then precision := (fields[i] as TFMTBCDField).Precision;
  19.             end;
  20.           end;
  21.     finally
  22.       FieldDefs.EndUpdate;
  23.       end;
  24.     end;
  25. end;  
  26.  
« Last Edit: August 17, 2016, 01:39:51 am by Geepster »

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: TDataSet.InitFieldDefsFromfields Bug
« Reply #1 on: October 15, 2016, 06:39:39 pm »
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
« Last Edit: October 20, 2016, 02:25:02 pm by LacaK »

 

TinyPortal © 2005-2018