• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi:在OnBeforePost事件中取消TDataSet.Post(Delphi:CancelingaTDataSet.Postinan ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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:这种取消数据库操作的方法也在帮助系统深处被描述为"正常"的方式来实现这一点---这是我从最初得到这种技术的地方)。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
在DELPHI中HOOK程序的编写发布时间:2022-07-18
下一篇:
Delphi在创建和使用DLL的时候如果使用到string,请引入ShareMem单元 ...发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap