Run Oncalcfield only when pressing [Enter]

Asked

Viewed 155 times

1

I have a DBGrid which searches several records recorded in the table just when the form is opened, this should show exactly everything that has saved in the table.

There are some fields calculated with the event OnCalcFields that soon when opening the form already return and show the calculated value in the columns, and this can not happen.

I intend that after showing the recorded data in the table, it would only perform the event calculation OnCalcFields when the user clicked on a button, or pressed the key Enter.

Can anyone say if you have how to do it? If yes you could give an example or a direction of how to do it?

  • Puts in the OnKeyPress the algorithm in the OnCalcFiends, which only calculates if it is [Enter]

  • I tried that way, but it didn’t work, it loses field references

  • Create a control variable in the form, change its value to true when the user clicks on that button, and in Oncalcfields, start with "if not control then Exit;"

1 answer

2

I suggest you modify the field from Calculated to Date. Schedule in the event KeyDown of DbGrid something like

begin
  if Key = VK_RETURN then
  begin
    Nome_Tabela.Edit;
    Nome_TabelaQTD.AsInteger := Nome_TabelaEVENTO.AsInteger * Nome_TabelaEVENTO2.AsInteger;
    Nome_Tabela.Post;
  end;
end;

I do not use the fields calculated exactly by these scenarios. I’ve had cases where the processing was gigantic exactly by the amount of records. In this example the processing is summarized only to the necessary cases.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.