Delphi:在OnBeforePost事件中取消TDataSet.Post(Delphi: Canceling a TDataSet.Post in an OnBeforePost Event)

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;

Calling the method Abort (from the unit System, if I recall correctly) raises a silent EAbort 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).

 

在主数据输入屏幕上,OnBeforePost事件中有一个OK / Cancel对话框。




    • em>让事情顺利进行

  • 取消现在做一个 Dataset.Cancel;



这是什么意思,回滚任何更改并将数据集置于浏览模式。



这对大多数客户来说都不错,但是我们被问及是否可以更改为




    • 取消,中止帖子并保持编辑模式,保留当前的更改。



如果他们想取消,他们可以使用取消按钮。



查看源代码程序TDataSet.Post; 它看起来不可能使用



任何人都有任何想法可以做到这一点吗?



跟进:这是我现在如何选择处理它



  case MessageDlg('保存C挂起?',mtWarning,[mbYes,mbNo,mbAbort],0)
mrYes:;
mrNo:Dataset.Cancel;
mrAbort:中止
mrNone:中止
结束

解决方案

调用方法 / code>(从单元 System ,如果我记得正确)引发了一个静默的 EAbort 异常,仅取消当前操作。 (btw:这种取消数据库操作的方法也在帮助系统深处被描述为"正常"的方式来实现这一点---这是我从最初得到这种技术的地方)。

posted on   癫狂编程  阅读(303)  评论(0编辑  收藏  举报

编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
好的代码像粥一样,都是用时间熬出来的
点击右上角即可分享
微信分享提示