Solved

Calculated Fields - How to

Posted on 1998-10-27
3
281 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE2 application frozen on Windows 10 10 309
can't find the executable in Simulator 1 90
Delphi Yen format 3 31
Wincontrol not (correctly) drawn 15 37
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

18 Experts available now in Live!

Get 1:1 Help Now