0

I am using TADOConn and TADODataSet units pulling data and connected to TDataSources and TDBGrids. I have my DBGrids displaying information properly and editing information in the detail view accurately reflects in the backing database.

What I would like to do is have it so that an update to a field in the detail DBGrid causes a refresh on both data sets so that the most up-to-date data is always displayed.

I have tried putting the refresh calls in several event handlers at various levels of DB access but they all seem to have a similar (but different) issue of reentry.

The best I've been able to come up with so far is getting the Master view updated by calling refresh on the details DBGrid.onColExit event.

If I leave the refresh calls out all together the updated information isn't displayed until the next time the application is run.

Any ideas of how to achieve this? Am I going about it the wrong why? Thanks in advance.

dpsthree
  • 2,225
  • 4
  • 21
  • 23

1 Answers1

1

You imply that the changes you make in the DBGrid are posted to the database but are not displayed in the grid or maintained in its dataset and that you must get them back from the database. All the dataset components I have used maintain its copy of the data including all the changes that passed through it to the database. If you expect the data to be changed by triggers or another process, you may need to refresh the data. Then you will have to deal with the possibility that the current record position is lost, i.e. the current record was deleted in the database.

I would try using the Dataset.AfterPost event to initiate the refresh. And I would consider using a Timer to delay the refresh if strange things happen.

crefird
  • 1,590
  • 11
  • 17
  • This might work, I'll give it a try. The only thing I see as being a problem is that regardless of where I place a delay it will still be in the same thread of execution that has the re-entrant issue. I'll post back with some results. – dpsthree Sep 25 '11 at 16:46
  • One purpose for the Timer is to break the chain of execution that could result in re-entrant problems. The other purpose is to allow other things to occur before the refresh which can reduce the number of refreshes needed. – crefird Sep 25 '11 at 17:35
  • No luck, since the timer has to be fired off somewhere within the event handler chain we are just delaying the inevitable. The only solution I have been able to come up with is a standalone update button that refreshes both datasets independently. – dpsthree Sep 27 '11 at 15:32
  • I was able to get this working using a combination of things. I started by adding a timer, and waiting for {insert your event of choice} to be fired. It was in that event that I started the timer. Since we wait to start the timer when we know the data has hit the database we can be sure that it will wait until we are finished. Then I set the timers event method to refresh first the master, then the detail views. Since the timer event IS in fact outside the update thread of execution we avoid re-entrant issues and guarantee the data has gone through. – dpsthree Oct 04 '11 at 17:22