Subject Re: [IBO] How add calculated fields at R/T w/ default fields??
Author G. Allen Casteran
Helen,

Thanks for the info... More points below.

At 12:55 PM 11/3/2001 +1100, you wrote:
<snip>
> >Here is what I have tried:
> >
> >//TPaymentsData is an TIBODataset descendant, which is a TDataset
> >descendant
> >procedure TPaymentsData.DoAfterOpen;
>
>I'm sure that you could not add a new object to the dataset after the
>dataset is open. At the latest, I would think (if you could do it at all)
>it would have to be (a) before Prepare and (b) while the dataset is in an
>unprepared state.

Good point, I'll look into this.


> > var
> > Fld : TField;
> > begin
> > // Add WHCode calcd field
> > Fld := TField.Create(Self);
> > Fld.FieldKind := fkCalculated;
> > Fld.FieldName := 'WHCodeCalc';
> > Fld.Calculated := True;
> > Fld.Index := Fields.Count; // <-- problem: does not set, stays at
> >-1 ??
>
>Fields.Count won't be available if the dataset isn't prepared. If it is
>returning -1 in the AfterOpen event then it looks as if your dataset isn't
>even prepared, let alone open.

The Fields.Count is getting the correct value. Later when doing a
FieldByName() the field IS found, but it's Index is -1. InfoPower uses the
Field.Index to map the field to their grid control. That is one reason I
need to have the Index set to a valid value.


>Also, I notice that you haven't assigned a FieldType to the calculated
>field and you also haven't subclassed TField to the descendant you
>want. TField is an abstract base class so you must do this.

Another good point! This goes in the Homer Simpson category.... DOH!!!


>As I said, I don't know whether TDataset lets you add to the Fields[]
>array at runtime *at all*. What requirement do you have that prevents you
>from creating the calculated field at design time?
The dataset object is created as part of a business object framework. This
is all created in code. Except for this one snafu, it all works great.

Allen.