防止Delphi中的表单停用6 [英] Prevent Form Deactivate in Delphi 6

查看:142
本文介绍了防止Delphi中的表单停用6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Delphi 6应用程序,它使用非格式格式进行并行编辑。在FormClose事件中,我们检查条目是否是正方形,如果没有,则阻止关闭。

We have a Delphi 6 application that uses a non modal form with in-grid editing. Within the FormClose event we check that the entries are square and prevent closure if they're not.

但是,如果用户点击主窗体后面的原始表单消失在后面(如你所料),但是这允许用户移动到主屏幕上的新记录,而没有对网格的更改进行验证。

However, if the user clicks on the main form behind then the original form disappears behind (as you'd expect) but this allows the user to move to a new record on the main screen, without their changes in the grid having been validated.

我已经尝试了FormDeactivate事件,它发射,但似乎没有任何机制来阻止停用(与FormClose事件Action参数不同)。
我从网格中尝试过OnExit,但是在停用时不会触发。
我试图捕获WM_ACTIVATE消息并设置Msg.Result = 1但这没有任何效果(可能是因为另一个WM_ACTIVATE消息被发送到主窗体?)。

I've tried the FormDeactivate event, which does fire but doesn't seem to have any mechanism to prevent deactivation (unlike the FormClose events Action parameter). I tried the OnExit from the grid, but it doesn't fire on deactivation. I tried trapping the WM_ACTIVATE message and setting Msg.Result = 1 but this has no effect (possibly because another WM_ACTIVATE message is being sent to the main form?).

所以,我正在寻找有关如何(有条件地)当用户点击另一个表单时阻止表单停用的想法。
(PS我不想将表单样式更改为fsStayOnTop)

So, I'm looking for ideas on how to (conditionally) prevent the deactivation of a form when the user clicks on another form. (PS I don't want to change the form style to fsStayOnTop)

感谢

推荐答案

感谢大家的帮助和建议。

Thanks to everyone for their help and suggestions.

这是我去过的解决方案:
在网格表单'(例如Form2)...

Here's the solution I went with: In the 'Grid Form' (eg Form2) ...

public  
    PricesNotSquare: boolean;  

在FormDeactivate事件中,将PricesNotSquare设置为true,如果它们不匹配。

In the FormDeactivate event, set PricesNotSquare to true if they don't match.

在主窗体的OnActivate事件中,...

In the OnActivate event of the Main Form, ...

  if Assigned(Form2) and (Form2.PricesNotSquare) then  
  begin  
      ShowMessage( 'Please ensure the total Prices match before leaving the form' );  
      Form2.Show;  
      exit;  
  end;  
  // other form activate stuff here  

原来是一个简单的解决方案,刚刚一段时间得到它。

Turned out to be a simple solution, just took a while to get it.

似乎工作正常,但如果有问题,那么我将纳入发送消息的想法。

Seems to work fine, but if it has issues then I'll incorporate the idea of sending a message.

这篇关于防止Delphi中的表单停用6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆