Jump to content

DBGrid not showing Calculated field correctly


eelias

Recommended Posts

Hi there!

 

I have a master detail form with a dbgrid connected to a DBISAM TTable. 

 

The master grid has a column TOTAL, that is linked to the same column on the TTable. It is a calculated field

 

On the OnCalcFields i have a loop on the detail table (another DBISAM TTable) that calculates the total and stores the value on the master:

procedure TDMMainG.TablePedidoCalcFields(DataSet: TDataSet);
var
  total : Currency;
begin
  total := 0;

  TablePedidoItPesq.First;
  while not TablePedidoItPesq.Eof do
  begin
    total := total + (TablePedidoItPesq.FieldByName('valor').AsCurrency * TablePedidoItPesq.FieldByName('qtd').AsFloat);
    TablePedidoItPesq.Next;
  end;

  DataSet.FieldByName('total').Value := total;
end;

With a breakpoint on this code I can see that the TOTAL is getting calculated right.

 

However on the DBGrid is shows only one value as the same for all rows. Sometimes the first, sometimes the last. I have not found why.

 

I have tried fetchall, recno, etc and in any situation is the same.

 

What can I do to fix this situation?

 

Thanks

 

Eduardo

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...