Board index » delphi » --> Calculating A Calculated Field <--

--> Calculating A Calculated Field <--

How do I get a calculated field to calculate?  For instance, I have a Qty
field and a Price field in my InvDet file.  I want to create a "Ext"
("Virtual") field that will be Qty * Price.  I can add a new field, and call
it "Ext", and call it a Calculated field of type float, but I can find no
place to do the calculations at.  Where do I handle this?

Thanks,
Jesse

 

Re:--> Calculating A Calculated Field <--


Jesse Castleberry <D...@iThink.net> wrote in article
<6dfchl$8a...@news10.ispnews.com>...

Quote
> How do I get a calculated field to calculate?  For instance, I have a Qty
> field and a Price field in my InvDet file.  I want to create a "Ext"
> ("Virtual") field that will be Qty * Price.  I can add a new field, and
call
> it "Ext", and call it a Calculated field of type float, but I can find no
> place to do the calculations at.  Where do I handle this?

> Thanks,
> Jesse

I wouldn't store a calculated field in a database file.  It violates
normalization rules because the field can be generated from the available
data.
If the calculated field is on a form, just put afterupdate events on the
input fields that update the display control (textbox).  You could always
do a query with a calculated field for reporting purposes.

I hope that helps :)
--

=======================================
codi...@airmail.NOSPAM.net
bgrav...@vha.NOSPAM.com
=======================================

Re:--> Calculating A Calculated Field <--


Quote
Jesse Castleberry wrote:

> How do I get a calculated field to calculate?  For instance, I have a Qty
> field and a Price field in my InvDet file.  I want to create a "Ext"
> ("Virtual") field that will be Qty * Price.  I can add a new field, and call
> it "Ext", and call it a Calculated field of type float, but I can find no
> place to do the calculations at.  Where do I handle this?

> Thanks,
> Jesse

The Dataset has an event called OnCalcField
In this event you just add your calculations :
Query1MyCalcField.AsFloat:=Query1Qty.AsFloat*Query1Price.AsFloat;

No need to be editing of something else...

Regards,

Frdric GUILLIEN

Re:--> Calculating A Calculated Field <--


Try TTable.OnCalcFields...

HTH

JdV!!

Quote
Jesse Castleberry wrote:

> How do I get a calculated field to calculate?  For instance, I have a Qty
> field and a Price field in my InvDet file.  I want to create a "Ext"
> ("Virtual") field that will be Qty * Price.  I can add a new field, and call
> it "Ext", and call it a Calculated field of type float, but I can find no
> place to do the calculations at.  Where do I handle this?

> Thanks,
> Jesse

--
========================================================================
Jan de Visser                          etmjdvi@_aom_.ericsson.se
M?/ETX/A/B NMAC Team SAC               Underscores
tel. +46 31 74 71890                   ECN 865 71890
                    Vette pech voor de kabouters!
========================================================================

Re:--> Calculating A Calculated Field <--


In article <01bd4638$bc545c00$83830...@sdarityhp2.corp.vha.com>, "VHA PC Development" <codi...@airmail.net> wrote:

Quote
>Jesse Castleberry <D...@iThink.net> wrote in article
><6dfchl$8a...@news10.ispnews.com>...
>> How do I get a calculated field to calculate?  For instance, I have a Qty
>> field and a Price field in my InvDet file.  I want to create a "Ext"
>> ("Virtual") field that will be Qty * Price.  I can add a new field, and
>call
>> it "Ext", and call it a Calculated field of type float, but I can find no
>> place to do the calculations at.  Where do I handle this?

>> Thanks,
>> Jesse

>I wouldn't store a calculated field in a database file.  It violates
>normalization rules because the field can be generated from the available
>data.

He doesn't put it in the Database, he adds it to his Dataset component.

The Graphical Gnome (r...@ktibv.nl)
Sr. Software Engineer IT Department
-----------------------------------------
The Unofficial Delphi Developers FAQ
http://www.gnomehome.demon.nl/uddf/index.htm

Re:--> Calculating A Calculated Field <--


In article <6dfchl$8a...@news10.ispnews.com>, "Jesse Castleberry"

Quote
<D...@iThink.net> wrote:
>How do I get a calculated field to calculate?  For instance, I have a Qty
>field and a Price field in my InvDet file.  I want to create a "Ext"
>("Virtual") field that will be Qty * Price.  I can add a new field, and call
>it "Ext", and call it a Calculated field of type float, but I can find no
>place to do the calculations at.  Where do I handle this?

Use the onCalculate event of your dataset (TQuery or TTable).

There you say something like.

Dataset.FieldbyName('Ext').AsFloat := dataset.FieldByName('QTY').AsFloat *
                dataset.FieldByName('Price').AsFloaf;

The Graphical Gnome (r...@ktibv.nl)
Sr. Software Engineer IT Department
-----------------------------------------
The Unofficial Delphi Developers FAQ
http://www.gnomehome.demon.nl/uddf/index.htm

Re:--> Calculating A Calculated Field <--


Hi Jesse,

If you add a Calculated field to a TQuery or TTable, the place to set its
value is in the OnCalcFields handler.

Simply add a line to this handler, something like:-

Query1Ext.AsFloat := Query1Qty.AsFloat * Query1Price.AsFloat;

and hey presto!

Other Threads