Pages: 1
Print
Author Topic: How to stop File - > Close or Window Close functionality when validation fails.  (Read 1182 times)
tsrsgm
Member

Posts: 7


« on: October 17, 2010, 11:51:23 PM »

Hi

In my application, i need to do some validation when user choose File -> Close or Window Close in the XMetal. If the validation fails it returns false, then the Document should not be closed, else then let the window/document closed. Could u pls suggest some work around of this issue. Thanks a lot in advance.

Thanks,
Sridhar
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1534



WWW
« Reply #1 on: October 18, 2010, 02:12:18 AM »

You will likely need to override the File > Close and File > Exit functionality to do this.

Have a look at the Programmers Guide topic titled "File operations".
http://na.justsystems.com/webhelp/en/xmetaldeveloper/pg/6.0/pg.html#File%20operations
Logged
tsrsgm
Member

Posts: 7


« Reply #2 on: October 18, 2010, 03:41:30 AM »

Hi Derek,

Thank you for reply. Could you please share some code snippet regarding the same.
Thank you in advance.

Sridhar
Logged
tsrsgm
Member

Posts: 7


« Reply #3 on: October 18, 2010, 05:01:33 AM »

Hi Derek,

In my application we are using "On_Document_Close" macro, when i choose File -> Close or window Close this macro being called. Please let me know the code snippet i should put in this macro. So that the document should not be closed after performing the certail validations.

Thanks,
Sridhar
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 1534



WWW
« Reply #4 on: October 18, 2010, 03:48:14 PM »

You cannot stop a document from closing in the event On_Document_Close as the close process has already begun.

In order to stop a document from closing you will need to override the File > Close action. See "File operations" as I have previously noted.

When you override that action a document will not close unless you specifically tell it to close. In the table for that help topic you will see the APIs you need to call to give you the "default" behavior for the action. If you do not call the API then the default behavior will never occur (and in this case the user will never be able to close a document).

In your case your logic might be something like this:

1) Do validation or whatever else you like to obtain a result of some kind.
2) Create a boolean based on that result.
3) Do an if...then type of check on the boolean. Perhaps something similar to this:

if (bool_allowDocumentToClose = true) then
   ActiveDocument.Close()
else (bool_allowDocumentToClose = false) then
   Application.Alert("Sridhar says: You cannot close this document because...")
end if

Logged
tsrsgm
Member

Posts: 7


« Reply #5 on: October 21, 2010, 01:36:33 AM »

Thank you for help Derek.

I got the expected result.

Regards,
Sridhar
Logged
Pages: 1
Print
Jump to: