Jump to content

DBGrid not showing Calculated field correctly


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);
  total : Currency;
  total := 0;

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

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

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?





Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...