I opened Excel table using ADO (though it is probably the same as any other database: adoconnection, adotable, datasource) and display it in ReadOnly DBGrid. And I have DBEdit to edit some value in currently selected row.
But how to save it? I tried adotable.Post on FormClose but it throws error that "dataset not in edit or insert mode".
Do I need to call adotable.Edit in DBEdit OnEnter and Post OnExit?
Post
is automatically called when the user navigates to another record.
The only time you need to call Post
is if the currently selected record has pending changes at the time you close the form.
But even then, you don't have to call Post
explicitly: there's a helper function CheckBrowseMode
you can use instead. If the data set is in edit mode, CheckBrowseMode
checks if there are any modifications. If not, it cancels the edit, otherwise, it posts those changes. CheckBrowseMode
won't raise any exception if the data set is already not in edit mode, only if the data set is closed (which shouldn't be possible in your case).