Board index » delphi » Need help with OnClose Event

Need help with OnClose Event

This is probably a real simple one. Before the user can close a form, I need
to check that all input components on the form contain appropriate entries.
This is something that can't be determined until the user is finished with
all data entry and closes the form. At that point, I want to add some code
before the form closes to check the input and, if necessary, popup a warning
message and return the user to the offending component.

If the user exits by using the "Close" button that I've put on the form,
there's no problem; I check the input and only if everything is okay do I
call the Close method. If, however, the user closes the form using the system
menu (the X at the upper-right of the screen) it seems to be too late; I can
check the input, but I don't seem to be able to stop the form from closing.

Does anyone have any suggestions?

Thanks,

Todd Franzen
Todd.Fran...@milliman.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

 

Re:Need help with OnClose Event


Todd,
  You will probably be better off implementing your code in the OnCloseQuery
as oppsed to the ONClose event.
              Good Luck!!
   Dave
http://www.erols.com/dparsons

Quote
To...@my-dejanews.com wrote in message <6piecc$1h...@nnrp1.dejanews.com>...
>This is probably a real simple one. Before the user can close a form, I
need
>to check that all input components on the form contain appropriate entries.
>This is something that can't be determined until the user is finished with
>all data entry and closes the form. At that point, I want to add some code
>before the form closes to check the input and, if necessary, popup a
warning
>message and return the user to the offending component.

>If the user exits by using the "Close" button that I've put on the form,
>there's no problem; I check the input and only if everything is okay do I
>call the Close method. If, however, the user closes the form using the
system
>menu (the X at the upper-right of the screen) it seems to be too late; I
can
>check the input, but I don't seem to be able to stop the form from closing.

>Does anyone have any suggestions?

>Thanks,

>Todd Franzen
>Todd.Fran...@milliman.com

>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:Need help with OnClose Event


One way of doing this would be to trap the WM_DESTROY message and only let it
proceed if everything's OK

Charles Johnson

Re:Need help with OnClose Event


Dave:

That's just what I was looking for! I hadn't used the OnCloseQuery before and
wasn't familiar with it. I knew it'd be something simple!

Thanks much!

Todd

In article <6piphc$kp...@winter.news.erols.com>,
  "Dave Parsons" <dpars...@NOSPAM.erols.com> wrote:

Quote
> Todd,
>   You will probably be better off implementing your code in the OnCloseQuery
> as oppsed to the ONClose event.
>               Good Luck!!
>    Dave
> http://www.erols.com/dparsons

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:Need help with OnClose Event


there are several solutions:
1. open the form, and select it
2. in the events page, of the object inspector, select OnCloseQuery
3. double-click it, and in the code call the close button OnClick event handler.
like that:
? if your buton is called closeBtn, write:? closeBtnClick(closeBtn);
this will call the onClick method of the button each time user closes the form
using the system menu (or the 'X' button). btw: thats called closeQuery (closing
using the system menu)

another way is disabling the system menu and the 'X' button:
1. goto the object inspector after selecting the form
2. double-click? borderIcons and set biSystemMenu to false
that way, the user must click the close button in order to close the form

if you already wrote the code in OnCloseQuery event handler, you can prevent the
closing by setting the CanClose var to false.

cya

Quote
To...@my-dejanews.com wrote:
> This is probably a real simple one. Before the user can close a form, I need
> to check that all input components on the form contain appropriate entries.
> This is something that can't be determined until the user is finished with
> all data entry and closes the form. At that point, I want to add some code
> before the form closes to check the input and, if necessary, popup a warning
> message and return the user to the offending component.

> If the user exits by using the "Close" button that I've put on the form,
> there's no problem; I check the input and only if everything is okay do I
> call the Close method. If, however, the user closes the form using the system
> menu (the X at the upper-right of the screen) it seems to be too late; I can
> check the input, but I don't seem to be able to stop the form from closing.

> Does anyone have any suggestions?

> Thanks,

> Todd Franzen
> Todd.Fran...@milliman.com

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp?? Create Your Own Free Member Forum

?

--
@ Itamar Benzaken - ita...@writeme.com
@ Creator of HTML Constructor
@ Website - http://come.to/htmlconstructor
@ ICQ Pager - http://wwp.mirabilis.com/141070
@ "You can lead a horse to water,
@?? but if you can get him to float on his back you've really got something."
?

Other Threads