[DUG] Which event to use

David Brennan dugdavid at dbsolutions.co.nz
Sun Oct 18 12:24:43 NZDT 2009


We centralise all data responding to new field values into the
TDatasource.OnDataChange event. If Field is nil then some major change just
happened (eg a new record being selected). If Field is assigned then that is
the field which just changed so you can check if Field is one of the fields
which should modify the price and if so call your routine for recalculating
the price.

 

If you also need to initialise your price for each record while opening the
dataset then you will need logic somewhere else as well (since OnDataChange
is only called for the selected record in certain situations or when a field
value changes) but hopefully you are storing the price in a field anyway so
that isn't an issue.

 

David.

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Charlie
Sent: Sunday, 18 October 2009 10:27 a.m.
To: delphi at delphi.org.nz
Subject: [DUG] Which event to use

 

I'm using BDS 2006, InfoPower dbGrid and InfoPower dbComboLookups. My
application is for orders that are placed to purchase the manufactured
drawer boxes and uses master-detail tables; namely orders and orderdetail.
Some of the detail data is entered in either dbEdits or dbLookups. These are
used for data that is the same for each detail record. The dbGrid is used
for the particulars for the items to be manufactured; namely, quantity,
width, depth, height, and up to 7 options, the square foot price for the
drawer box and the extended price (computed as square foot price * quantity
+ cost of the options selected). To determine the square foot price the
program has to use the type of wood chosen for the drawer boxes, the height
of the box, the price table and determine if the square feet for the box is
greater than the minimum 1.5 square feet.

Sometimes the program finds the correct price and sometimes it doesn't on
the same order. I have a procedure that 'calculates' the price. I think that
perhaps I'm over calling this procedure. 

The fields for the order and orderdetail tables are persistent.

Currently there are several infopower lookup controls which have an
OnCloseUp event. Some of these are attached to the infopower grid. The
'calculate' procedure is called in this event. The persistent fields call
the 'calculate' procedure in the OnValidate and/or the OnExit event. And to
top this off I have the dbGrid calling the 'calculate' procedure for the
OnCellChange event. I guess I wanted to get the price figured out no matter
what happened, lol. 

So the question is: What is the way I'm supposed to get the price figured
out? Namely, do I use the DataSet's OnDataChange event, do I use the
persistent fields' OnValidate event or is it better to use the OnChange
event, do I use the dbGrid's OnCellChange event, or do I use the controls
OnExit or OnCloseUp event. Or should I do something different?

 

I've learned that most folks recommend against using a dbGrid the way that I
am; but my bottom line is I need for each record to have the correct square
foot price and the corresponding total for that record.

Thank you for any help.

Charlie

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20091018/04c9bee0/attachment.html 


More information about the Delphi mailing list