I'm trying to create a calculated field (Cost
) in a database table for values entered by the user for example price and quantity like in the example below :
Cost = Price * Quantity
I searched but I couldn't find a clear way how to it.
Create a calculated field from the Field Editor.
Currency
), and check the radio button for Calculated, and then click OK.Add something similar to the code below, adjusting as needed for your field names:
procedure TCustForm.yourQueryCalcField(DataSet : TDataset);
begin
DataSet.FieldByName('Cost').AsCurrency :=
DataSet.FieldByName('Price').AsCurrency*
DataSet.FieldByName('Quantity').AsInteger;
end;