Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is it possible to manually execute the "OnCalcFields" event?

Say that I temporarily want to disable the OnCalcFields event (eg. by setting cdsCalcFields := nil) during a time-consuming operation on a TClientDataSet. How can I tell the TClientDataSet to perform a recalculation of the calculated fields when I re-attach the OnCalcFields method?

Another situation that might require a manual recalculation is the situation where some of the calculated fields are depending on other datasets (eg. a calculated field is used to temporarily hold some aggregated value from the other dataset). This would work fine in most cases because the OnCalcFields events are executed often enough to get the correct value from the other dataset. But in some circumstances a recalculation is necessary to obtain the correct value from the other dataset.

Setting the AutoCalcFields property to False might also get you into some situation where a manual recalculation is desired.

I've seen several explanations on how to reduce the execution of the OnCalcFields event, but I can't find a simple way to just perform a recalculation...

Any suggestions?

like image 877
Jørn E. Angeltveit Avatar asked Feb 24 '23 02:02

Jørn E. Angeltveit


1 Answers

Calculated fields are calculated when records are retrieved from the database, so call Refresh (or Close -> Open) on the dataset to force a re-calculation.

(Regarding the comments on the question), to force a re-calculation on only one record you can call RefreshRecord on the dataset. If the particular dataset descendant does not implement the method, an Edit followed by a Cancel call would achieve the same.

like image 194
Sertac Akyuz Avatar answered Mar 06 '23 00:03

Sertac Akyuz