I’m planning to write an un-do feature for use in a TDBGrid hooked up to a TTable (BDE). I want it to work at the grid cell level.
I’d like some suggestions on a good way to implement this.
I plan to keep a list of records that changed, the field name, and their former values.
What I need, I believe, are an OnEnter and OnExit for cells.
TDataSet.BeforeEdit is half of what I need, I think. But, TDataSet.AfterEdit is a bit misnamed — it’s called not after the edit is completed, but “after the TDataSet enters the edit mode” (to quote the help system.)
TField.OnChange would work though… I think …
My thinking is that AfterEdit will grab the contents of the cell. And TField.OnChange will log the change to a stack I keep. (Thank goodness for Delphi’s Generics. I never knew what I was missing before we had them!)
Any suggestions on how my thinking, caveats, or better ways to do this?
PS Standard mea culpa: Yes, yes: the BDE is deprecated, I shouldn’t be using it, yada, yada, yada. Tell that to my boss who has me maintaining 1.5 million lines of legacy code. Yes, yes: someday the BDE will go away and we should be proactive and make the move now. We know. Thank you.
As per Robert’s request, my comment(s) rewritten as an asnwer.
Don’t cells already support undo by typing Ctrl-Z or Esc?
Or if you want to keep a stack of edits to multiple cells and have “undo” revert them one by one then you could combine dataset and field events. The dataset
OnBeforeEditwill give you the base for all cells, each field’s onchange will give you itsOnAfterEditwhich would render the same value as an (imaginary)Field.OnBeforeEditwhen the user comes back to edit the same cell again.