OnCalcFields Hint

The Oncalc event is called VERY often, and can be unnecessary and time consuming lets say you have a calculated field, and that need calclating according to some field that the user edits (i.e)


MyCalcField.AsInteger := Table1Field1.AsInteger + 10;


Now, should you decide to go and sequentially go through every record in the table, that is a lot of on calc events occuring! They are also possibly unnecessary if you are not doing processing involving the MyCalcField.

I would suggest turning this event off before processing, and the turning it back on after processing i.e. :


Procedure TForm1.BigProcessingFunction;

begin

  Table1.OnCalcFields := nil;

 

 <Do massive processing here!>

 

  Table1.OnCalcFields := Table1OnCalcFields;

 end;

 


of course the fields are not calculated during the processing time, which can be a bummer, but if you need the result of a specific field, you can calculate that during the massive processing!

This method of avoiding unnecessary code can be used all over the place and make a significant difference to the speed of an App.