[DUG] Which event to use

David Brennan dugdavid at dbsolutions.co.nz
Mon Oct 19 09:35:42 NZDT 2009


TDatasource.OnDataChange will fire each time there is an edit to one of the
fields. However note with many controls if the user changes the value it
doesn't send the new value to the field immediately, this often only happens
when the user tabs out or hits enter (depends on the controls but tab should
always do it). 

 

By if field is assigned I meant the code:

 

If Assigned(Field) then begin

                ...

 

Note that this is the same as:

 

If Field <> nil then begin

                ...

 

I can't help feeling that your total price won't be affected directly by all
23 fields, instead it is probably only affected by a few fields (eg maybe
Quantity, Square Foot Price and Discount). So you should only need to update
total price when one of those three changes. Note that
TDataSource.OnDataChange will fire if a field value is changed in code too
so you CalculatePrice routine will trigger OnDataChange with a parameter of
SquareFootPrice.

 

David.

 

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Charlie
Sent: Monday, 19 October 2009 3:07 a.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Which event to use

 

Thanks David for your help.

RE: 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.

There are 24 fields for each orderdetail record. 23 of these have an effect
either on the square foot price or the total for the record. Of course the
square foot price has an effect on the total since the square foot price is
multiplied by the quantity and the square feet of the box. To this is added
the upcharges for various options to arrive at the total for the box.

12 of the 24 fields are always used for each box.

Am I right in understanding that the TDataSource.OnDataChange will fire each
time there is an edit to each of these 24 fields? By edit I'm thinking of a
change in the existing value in the control,  deleting the value in the
control, adding a value to the control. If any of these things occur in one
of the 23 fields this could effect either the square foot price or the
record total.

I'm not quite sure what 'If Field is Assigned' really means. 

There are two fields that are used to set values for all boxes for the
orders. The InfoPower dbLookupCombo (which I use for these) has a OnCloseUp
which I use for those two fields. But these values can be overridden by
corresponding fields for a record. Again I use the InfoPower dbLookupCombo
and it's OnCloseUp event to call the 'calculate' price method. It appears I
wouldn't have to do that if I use the TDataSource.OnDataChange event.

 

Appreciate your help, David. Thanks to all.

Charlie 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20091019/3c26a24a/attachment-0001.html 


More information about the Delphi mailing list