ginsonic
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(Da taSet: TDataSet);
begin
Table1.FieldByName('FULLNA ME').AsStr ing := Table1.FieldByName('FIRSTN AME').AsSt ring + ' ' + Table1.FieldByName('LASTNA ME').AsStr ing;
end;
For this work perfect but for Query not. Any HEEEEELLLLPPPP ??
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(Da
begin
Table1.FieldByName('FULLNA
end;
For this work perfect but for Query not. Any HEEEEELLLLPPPP ??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER