0

I use Delphi 10.2 with ComponentAce's Absolute Database framework. So my question here can pertain to TAbsQuery or, I presume, the conventional Delphi TQuery class.

My database has a date field named lastViewed. I have the RequestLive set to true so that any changes made to various fields in the current record are persisted to the table. Additionally, in my BeforeScroll event (i.e., prior to advancing to another record) the lastViewed field is updated to the current date. It works just fine. However, I have a menu option that displays a list of all records sorted by the last viewed date. In other words,

SELECT * FROM myTable ORDER BY lastViewed

It looks just fine when the results are initially shown in the DBGrid (TAbsGrid, in my case). But as I scroll down the list, the lastViewed field is updated and that record is pushed to the bottom of the grid. I would like the original order of the list to be preserved as I scroll up or down the list.

Turning LiveRequest to false will obviously trigger a database error when updating the DB fields in my BeforeScroll event.

The same issue would occur if, say, I want to show results for all records having the myFavoriteColor field with a RED value. Changing the myFavoriteColor value to GREEN, that row would disappear from my query results list.

Is there a way to keep the current query results in tact, while still being able to update the underlying table with new data?

Thank you for reading this.

  • 1
    You need to rethink your design. Leaving aside the fact that TQuery (and the Borland Database Engine it was designed for) have been obsolete for 20+ years, it's difficult to imagine anything more actively hostile to other users of the database than having the lastViewed fiekd updated as a user scrolls through a DBGrid. And it's utterly pointless. Except in very exceptional circumstances, a lastUpdated field is likely to convey more useful information at far lower overhead. – MartynA Jul 02 '21 at 21:58
  • Why in the world would you be updating the data every time it is viewed? It's ridiculous to do so - the fact that the user looks at data is immaterial for every purpose I could imagine. What should matter is the last time the record was modified. And if you insist on doing that, then you have to get used to exactly the behavior that you're experiencing - if you're sorting by `lastViewed`, and `lastView` is updated, it **properly and as expected** would move to the bottom of the view of the data. You can't stop it, because it's exactly what should be happening. – Ken White Jul 02 '21 at 23:00
  • And a clear reason why this should be a problem for you - what happens if the user views a record in the grid, moves to the next row, and then decides they want to back up to the previous row they looked at because they forgot something, and guess what? The rows no longer available for them to review again, because something (ludicrously) modified the row for no reason to make it change its index position. Can you say *extremely irritated and frustrated user*? How many dozens or hundreds of times will that happen per day to that user? How angry are they at the end of that day? – Ken White Jul 02 '21 at 23:04
  • To add to previous comments: Your *LastViewed* concept as you describe it is more a *LastDisplayed*. Because a record appeared on screen doesn't mean the user actually *viewed* it. – fpiette Jul 03 '21 at 06:19

0 Answers0