Delphi:在 OnBeforePost 事件中取消 TDataSet.Post
在我们的主数据输入屏幕上,我们在 OnBeforePost 事件中有一个确定/取消对话框。
- 确定让事情顺其自然
- 取消现在执行一个
Dataset.Cancel;
这会执行它的意图,回滚所有更改并将数据集进入浏览模式。
这对于大多数客户来说都很好,但我们被问到是否可以将其更改为
- 取消,中止帖子并保持编辑模式并保留当前更改。
如果他们想取消,可以使用取消按钮。
查看procedure TDataSet.Post;
的源代码,看起来不可能以这种方式使用事件。
有人对如何做到这一点有任何想法吗?
跟进:这就是我现在选择的处理方式
case MessageDlg('Save Changes?', mtWarning, [mbYes, mbNo, mbAbort], 0) of
mrYes: ;
mrNo: Dataset.Cancel;
mrAbort: Abort;
mrNone: Abort;
end;
On our main data entry screen, we have an OK/Cancel dialog in the OnBeforePost event.
- OK lets things take their course
- Cancel right now does a
Dataset.Cancel;
Which does what it's meant to, roll back any changes and puts the dataset into browse mode.
This is fine for most of the clients, but we have been asked if it can be changed to
- Cancel, Abort the Post and stay in edit mode with the current changes kept.
If they want to cancel, they can use the cancel button.
Looking at the source for procedure TDataSet.Post;
it does not look possible to use the event this way.
Dose anyone have any thoughts on a way this could be done?
Follow Up: this is how I have chosen to handle it now
case MessageDlg('Save Changes?', mtWarning, [mbYes, mbNo, mbAbort], 0) of
mrYes: ;
mrNo: Dataset.Cancel;
mrAbort: Abort;
mrNone: Abort;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
Abort
方法(如果我没记错的话,来自System
单元)会引发一个静默的EAbort
异常,该异常仅取消当前操作。 那应该有效。(顺便说一句:这种取消数据库操作的方法也在帮助系统深处的某个地方被描述为实现此目的的“正常”方法——这就是我最初获得这项技术的地方)。
Calling the method
Abort
(from the unitSystem
, if I recall correctly) raises a silentEAbort
exception, which cancels just the current operation. That should work.(Btw: this method of cancelling a databaset operation is also described somewhere deep in the help system as the 'normal' way to achieve this --- that's where I got this technique from originally).