Solved

Calculated Fields - How to

Posted on 1998-10-27
3
280 Views
Last Modified: 2010-04-06
Simple question. How do I define and access a calculated field in a table.

I have two field values i want to multiply, with the total going in the calculated field.

Thanks.
0
Comment
Question by:DougBennett
  • 2
3 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344651
0
 

Accepted Solution

by:
pc_melsa earned 10 total points
ID: 1344652
To add calculated fields, use the field editor, which is accessed by double clicking the TTable Component. Select the Define button, you'll nee to supply a new field name and the data type of the field.
Delphi 2,3 executes the procedure in the OnCalcFields event handler whenever there is need to recalculated field.
While in the OnCalcFields event handler, the dataset will be in dsCalcFields state.

Here is the example :

procedure MyForm.InventoryCalcFields(Dataset: TDataSet) ;
VAR
   CurrentPrice, LbsPerYard, YardsInStock : double ;
BEGIN
   CurrentPrice := MyTable['CostPerYard'].AsFloat ;
   LbsPerYard   := MyTable['LbsPerYard'].AsFloat ;
   YardsInStock := MyTable['CubicYards'].AsFloat ;

    // Assign value to the fields that are calculated
   MyTable['MarketValue'].AsFloat := CurrentPrice * YardsInStock ;
   MyTable['LbsInStock'].AsFloat := LbsPerYard * YardsInStock ;
END ;


Hope you'll satisfied.
0
 

Expert Comment

by:pc_melsa
ID: 1344653
Thank you very much !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now