Different ways to close form

Started by Jim Short, December 24, 2012, 06:18:20 PM

Previous topic - Next topic

Jim Short

12/24/2012

Test.odcl
Test.lsp

Check and uncheck events in odcl to see different arrangements.
See attachments. Please correct any oversights.

A Modal form with no form level events closes with:
Enter=1
Escape=2

As long as there are no buttons with focus, otherwise close will be suppressed.

To run some more code during enter and escape use:
OnCancel and OnOK
No form closes needed.

Returns:
Enter=1
Escape=2

To keep form up when enter pressed:
Use OnCancelClose and return true to suppress enter.

Enter is suppressed and escape returns 1, because OnCancelClose function has a reason parameter with 0 being enter and 1 being escape.

Enter suppressed
Returns:
Escape=1

Once OnCancelClose event has been selected, OnOK and OnCancel no longer have any affect.

Any coding then needs to go in the OnCancelClose event.

Like this:

(defun c:Test_One_OnCancelClose (Reason /)
   (cond
      (;;enter
         (= Reason 0)
         t
      )
      (;;cancel
         (= reason 1)
         (dcl_Form_Close Test_One 2)
      )
   )
)

Returns:
Escape=2

Escape can be any thing you choose so stay with 2 to be consistent.

Since OK is like enter would be, if it were not suppressed, and Cancel and ESC are the same thing, set Set button OK to close form with 1 and button Cancel to close with 2 to keep everything consistent.

(setq formReturn (dcl_Form_Show formName)) <<< corrected 10/27/2013 was:Open is:Show js

(cond
   (;; OK
      (= formReturn 1)
      returnVal1
   )
   (;;Cancel X ESC
      (= formReturn 2)
      returnVal2
   )
)

This helped me understand what is going on. I hope it helps you.
Merry Christmas,
Jim
Jim Short