Delphi Calculated Field
Calculated fields lets you display values that do not exit in any table in your database. Instead these values are computed at run time.
The following are steps to perform this said task and as follows;
1) select a Table or Query 2) display the field editor (by double clicking) 3) select NEW field as option 4) enter unique field name and select a valid type 5) click on OK button to save 6) goto your working form where your display (data aware) is present and double click on so 7) at the field editor 8) add this Calculated field you had just inserted earlier from steps 1) to 5) above 9) and save your work | now that you have just created the new field you must add the code to perform the calculation to the TTable's OnCalFields event handler as follows; 1) select the target TTable components in the data module 2) in the Object Inspector, select the Events page and double-click the OnCalFields event to open the code editor 3) add the following code to this event handler procedure TCustForm.OrdersTblCalcField (DataSet : TDataset); begin { calculate the balance due } OrdersTblAmountDue := OrdersTblItemsTotal.value - OrdersTblAmountPaid.value; end; Notice that this code uses the component names, not the field names. Also, notice how the Value property of the TField components is used to perform the calculation and store the result in the newly calculated field. |

