Jump to content

DBGrid not showing Calculated field correctly


eelias
 Share

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

Join the conversation

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

Guest
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.

 Share

×
×
  • Create New...