How to force update a DB grid?

Mawg says reinstate Monica picture Mawg says reinstate Monica · Nov 30, 2012 · Viewed 8.4k times · Source

I may have been too clever for my own good :-/

I have a table which holds some pressure measurements. These are always stored as PSI, but the user can select a radio group button to toggle between PSI and BAR.

In order to keep the code clean and and push work onto the database, I created a second table for configuration items, with a single row. One column psi_bar_conversion will take the value either 1 or 14.5 as the user toggles the radio group.

In Delphi, my query which ties to my DB grid is set up with statements like

SELECT ROUND(inlet_waterPressure_psi  /  
                  (SELECT psi_bar_conversion FROM configuration), 
             (SELECT float_precision FROM configuration))
       AS inlet_waterPressure, 
FROM measurements

All of which works just fine (and perhaps I am explaining too much).

All that I am tring to do is add some code in the function which handles the radio button toggle to force my DB grid to refresh its contents becuase I have just updated the value of configuration.psi_bar_conversion (but no direct field of my query, nor of my datasource).

Should I invoke Refresh() or Invalidate() or SomeOtherFunction() - of the DB grid, the query, the datasrouce? That's what is confusing me.

Thanks in advance for any help ....

Answer

Ken White picture Ken White · Nov 30, 2012

You need to close and then reopen the query to have the change in psi_bar_conversion and float_precision to take effect. The two sub-selects (for the values from configuration) only happen when the query is executed.