Solved

Calculated Fields - How to

Posted on 1998-10-27
3
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

628 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