I have a calculated filed 'Balance' which display the balance amount between two dataset fields and I used the next code to calculate its value:
var
Balance : Currency;
...
procedure TMyForm.MyQueryCalcFields(DataSet: TDataSet);
begin
if MyQuery.FieldByName('MyFirst Field').AsCurrency > 0 then
Balance := Balance+MyQuery.FieldByName('MyFirst Field').AsCurrency;
if MyQuery.FieldByName('MySecond Field').AsCurrency > 0 then
Balance := Balance-MyQuery.FieldByName('MySecond Field').AsCurrency;
MyQuery.FieldByName('Balance').AsCurrency := Balance;
end;
and I used TDBGrid
to display the result of my query , The dbgrid display the correct values until I start srolling its vertical scrollbars, in this case it shows wrong values.
I tried assigning '0' to the balance but its the same (Wrong values when start scrolling).
How I can make the dbgrid keep showing the right values?