Link to home
Start Free TrialLog in
Avatar of ginsonic
ginsonicFlag for Romania

asked on

Query and calculated fields

How can I add a calculated field to a query at runtime?

For a TTable I use:

  Table1.Close;

  for i := 0 to Table1.FieldDefs.Count - 1 do
    if Table1.FindField( Table1.FieldDefs[ i ].Name ) = nil then
      Table1.FieldDefs.Items[ i ].CreateField( Table1 );

  f := TStringField.Create( Table1 );
  f.Name := 'FULLNAME';
  f.FieldName := 'FULLNAME';
  f.Size := 50;
  f.Calculated := True;
  f.DataSet := Table1;

  Table1.OnCalcFields := Form1.Table1CalcFields;

  Table1.Open;
...
procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
   Table1.FieldByName('FULLNAME').AsString := Table1.FieldByName('FIRSTNAME').AsString + ' ' + Table1.FieldByName('LASTNAME').AsString;
end;

For this work perfect but for Query not. Any HEEEEELLLLPPPP ??
ASKER CERTIFIED SOLUTION
Avatar of dygj
dygj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ginsonic

ASKER

Thanks for support!