type
TForm1 = class(TForm)
Query: TADOQuery;
//...
procedure QueryCalcFields(DataSet: TDataSet);
private
FCalc : TStringField;
//...
end;
//...
var
i: Integer;
begin
with Query do begin
Close;
Prepared := False;
Sql.Clear;
Sql.Add('SELECT * FROM blabla_table');
// ...
Query.FieldDefs.Updated := false;
Query.FieldDefs.Update;
Query.Fields.Clear;
for i := 0 to Query.FieldDefs.Count - 1 do begin
if (Query.FindField(FieldDefs[i].Name) = nil) then
Query.FieldDefs.Items[i].CreateField(Query);
end;
FCalc := TStringField.Create(Query);
with FCalc do begin
FieldName := 'new_calc_field';
FieldKind := fkCalculated;
Size := 100;
DisplayWidth := 100;
DisplayLabel := 'Новое вычисляемое поле';
end;
FCalc.DataSet := Query;
Prepared := True;
end;
end;
procedure TForm1.QueryCalcFields(DataSet: TDataSet);
var
A,B : TField;
begin
A := Query.FieldByName('bla_bla_1');
B := Query.FieldByName('bla_bla_2');
if (A <> nil) and (A <> nil) then
FCalc.Value := IntToStr(A.AsInteger + B.AsInteger);
end;