Subject How add calculated fields at R/T w/ default fields??
Author allen@nisinc.com
I have a situation where I create a TIBODataset (like a TQuery
descended from TDataset) in code and would like to add some calculated
fields
to the result set. This needs to be done on the client at run-time. I
am not doing any of this visually and the default fields from the
server plus my
added calculated fields are all I need.

I have tried several ways and the fields seem to add to the fields
list of the dataset but the calculated fields I add have an
Field.Index of -1
regardless of how I try to assign the index value.

Here is what I have tried:

//TPaymentsData is an TIBODataset descendant, which is a TDataset
descendant
procedure TPaymentsData.DoAfterOpen;
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.Add(Fld);
inherited;
end;

Thanks,

Allen.