Adding Calc Fields at runtime
Adding Calc Fields at runtime
What is the best way to add fields (Calc fields) at runtime, (ie not using the fields editor in IDE)?
This question concerns common issues of using TDataSet. You can read more about this in the Delphi help.
In your case you can use something like this:
In your case you can use something like this:
Code: Select all
var
f: TField;
i: integer;
...
MyQuery.FieldDefs.Update;
for i := 0 to MyQuery.FieldDefs.Count - 1 do
f := MyQuery.FieldDefs[i].CreateField(MyQuery);
f := TFloatField.Create(MyQuery);
f.FieldName := 'Calc';
f.Calculated := True;
f.DataSet := MyQuery;
MyQuery.Open;