Solved

Calculated Fields - How to

Posted on 1998-10-27
3
278 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
Comment Utility
0
 

Accepted Solution

by:
pc_melsa earned 10 total points
Comment Utility
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
Comment Utility
Thank you very much !
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
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.

763 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

14 Experts available now in Live!

Get 1:1 Help Now