I have a TWebClientDataset with fields defined as
CoLicPrdLkUp := TClientDataSet.Create(Self);
CoLicPrdLkUpId := TIntegerField.Create(Self);
CoLicPrdLkUpSku := TStringField.Create(Self);
CoLicPrdLkUpName := TStringField.Create(Self);
CoLicPrdLkUpVersionId := TIntegerField.Create(Self);
CoLicPrdLkUpPrice := TFloatField.Create(Self);
CoLicPrdLkUpData := TStringField.Create(Self);
I am having an issue with CoLicPrdLkUpPrice. The property population is
CoLicPrdLkUpPrice.SetParentComponent(CoLicPrdLkUp);
CoLicPrdLkUpPrice.Name := 'CoLicPrdLkUpPrice';
CoLicPrdLkUpPrice.FieldName := 'Price';
CoLicPrdLkUpPrice.Required := True;
One observation is that the SetParentComponent is called before the FieldName is set. This method then checks to see if the FieldName is already present (via FieldList.Add, then CheckFieldName and FindField). At this point the FieldName is not set so it searches for a FieldName of "" (blank) so always returns not found. There is not an issue at this point but it does seem a pointless execercise.
The issue comes when CoLicPrdLkUp.AfterLoadDFMValues;
is called. Here TCustomClientDataset.InitFieldDefs (WebLib.CDS.pas) which adds all the TFieldDefs.
This issue is in the InitField sub procedure HandleChildField (below) where the TFloatField gets identified as a TNumericField (and gets added) and then as a TFloatField and an attempt is added again.
procedure HandleChildField(Child: TComponent);
begin
if Child is TStringField then
FieldDefs.Add((Child as TStringField).FieldName, ftString, (Child as TStringField).Size);
if Child is TBooleanField then
FieldDefs.Add((Child as TBooleanField).FieldName, ftBoolean, 0);
if Child is TAutoIncField then
FieldDefs.Add((Child as TAutoIncField).FieldName, ftAutoInc, 0)
else
if Child is TIntegerField then
FieldDefs.Add((Child as TIntegerField).FieldName, ftInteger, 0)
else
if Child is TLargeIntField then
FieldDefs.Add((Child as TLargeIntField).FieldName, ftLargeInt, 0)
**else **
** if Child is TNumericField then**
** FieldDefs.Add((Child as TNumericField).FieldName, ftInteger, 0);**
** if Child is TFloatField then**
** FieldDefs.Add((Child as TFloatField).FieldName, ftFloat, 0);**
Any ideas? Thanks.