Board index » delphi » dynamically add a calculated field

dynamically add a calculated field

In a special case using a dataset, I need to dynamically add a
calculated field. How can I do this?

I tried this:

procedure TdtmMain.ucdsBewegungAfterOpen(DataSet: TDataSet);
var
cfHabenField : TNumericField;
cfSollField : TNumericField;
begin
cfHabenField := TNumericField.Create(DataSet);
With cfHabenField Do
Begin
FieldKind := fkCalculated;
FieldName := 'cfHaben';
Calculated := True;
// DisplayFormat := MonFormat
End; { With }
DataSet.Fields.Add(cfHabenField);
{...}
end;

procedure TdtmMain.ucdsBewegungCalcFields(DataSet: TDataSet);
begin
With DataSet Do
Begin
FieldByName('cfHaben').AsFloat := 123.456;
{...}
End; { With }
end;

I get an error message "Field cfHaben doesn't have a quantity of data"
(translation of my german error message)

THX

 

Re:dynamically add a calculated field


Take a look at:

"Dynamically creating a TTable & fields at runtime"
http://community.borland.com/article/0,1410,16467,00.html

=Bill

Other Threads