
This event is fired to query if the dialog should be closed. Return a 1 to indicate that your program wishes to cancel the close action.
Each dialog that throws this event has its handler that takes this generic form:
Copy Code |
|---|
(defun c:FormName_OnCancelClose (bUserPressedEsc [as Boolean] /) ) |

NOTE: Never call Odcl_Form_Show from a dialog event handler or you will cause the stack to overflow. Always unroll a Odcl_Form_Show before taking the next action.
This example demonstrate how to achieve a loop without getting into a stack overflow.
The loop variable controls the continuation. Once set to Nil, the looping stops.
The action variable identifies which button the user pressed.
There are five possible ways the dialog can be closed and they all are covered in this example:
Copy Code |
|---|
;;================================================;; ;; ObjectDCL Best Practice Advice! ;; ;;================================================;; ;; Note: Never call Odcl_Form_Show from a ;; ;; dialog event handler or you will cause ;; ;; the stack to overflow. Always unroll ;; ;; a Odcl_Form_Show before taking the ;; ;; next action. ;; ;;================================================;; (defun c:ModalLooping () (odcl_loadproject "ModalLooping.odc" T) (setq loop T) (while loop (setq action Nil) (Odcl_Form_Show ModalLooping_ModalLoopingForm) (if (eq action "DoAction") (princ "...Executing action A...n") ) (if (eq action "DoOk") (princ "...Executing action B...n") ) (if (Not action) (or (princ "The user pressed Cancel, Escape or the X button...n") (setq loop Nil) ) ) ) (princ "The user is bored and now leaves back home...n") ) ;;================================================;; ;; OnClicked ActionButton event handler ;; ;;================================================;; (defun c:ModalLoopingForm_ActionButton_OnClicked () (princ "The user want to do action A...n") (setq action "DoAction") (Odcl_Form_Close ModalLooping_ModalLoopingForm) ) ;;================================================;; ;; OnClicked OkButton event handler ;; ;;================================================;; (defun c:ModalLoopingForm_OkButton_OnClicked () (princ "The user want to do action B...n") (setq action "DoOk") (Odcl_Form_Close ModalLooping_ModalLoopingForm) ) ;;================================================;; ;; OnClicked CancelButton event handler ;; ;;================================================;; (defun c:ModalLoopingForm_CancelButton_OnClicked () (princ "The user has cancelled...n") (setq loop Nil) (Odcl_Form_Close ModalLooping_ModalLoopingForm) ) ;;================================================;; ;; OnClose Dialog event handler ;; ;;================================================;; (defun c:ModalLoopingForm_OnClose (nUpperLeftX nUpperLeftY /) (princ "Dialog closed...n") ) ;;================================================;; ;; OnCancelClose Dialog event handler ;; ;;================================================;; ;; Returns ;; ;; T to prevent closing the dialog ;; ;; nil to allow closing the dialog ;; ;;================================================;; (defun c:ModalLoopingForm_OnCancelClose (bUserPressedEsc /) (princ "Dialog about to be closed...n") (if (eq bUserPressedEsc 1) (or (princ "The user pressed escape...n") (setq loop Nil) ) ) Nil ) ) |