Page 1 of 1

Do an action on CANCEL

Posted: Sat Mar 11, 2017 8:18 pm
by alepap
How do you do an action when CANCEL was pressed.

Code: Select all

STATIC FUNCTION XSample_3

/*
@ SAY..GETS (PIXEL BASED)

This sample demonstrates several @ DCSAY..GETs with automatic sizing
of the dialog window to the objects and an additional set of buttons
for OK and CANCEL.  The window is MODAL.  Coordinates are PIXEL-based.
*/

   LOCAL GetList := {}, dDate := Date(), nNumber := 12345.67, ;
         cString := 'This is a string', lLogical := .t., GetOptions

   SET DATE FORMAT TO 'mm/dd/yyyy'
   @ 10,1 DCSAY 'Enter a Date' GET dDate PICTURE '99/99/9999' ;
          SAYRIGHT GETSIZE 100
   @ 30,1 DCSAY 'Enter a Number' GET nNumber SAYRIGHT
   @ 50,1 DCSAY 'Enter a String' GET cString SAYRIGHT
   @ 70,1 DCSAY 'Enter Yes or No' GET lLogical PICTURE 'Y' SAYRIGHT

   DCGETOPTIONS ;
      WINDOWHEIGHT 300 ;
      WINDOWWIDTH 400  ;
      SAYWIDTH 120 ;
      PIXEL ;
      TITLE 'Data Entry' // Store options to GetOptions

   DCREAD GUI ;
      TITLE 'Pixel-Based GETs' ;
      BUTTONS DCGUI_BUTTON_OK + DCGUI_BUTTON_CANCEL ;
      MODAL ;
      OPTIONS GetOptions

// evaluate here if cancel was pressed
// if cancel is pressed, say "Hello Cancel is pressed" in a dialog.

RETURN nil
*** END OF EXAMPLE ***

Re: Do an action on CANCEL

Posted: Sun Mar 12, 2017 8:15 am
by rdonnay
Use the ABORTQUERY clause of DCGETOPTIONS

Code: Select all

DCGETOPTIONS ;
  ABORTQUERY MSG {|x|(DCMSGBOX 'Do you really want to cancel?' YESNO TO x),x}

Re: Do an action on CANCEL

Posted: Tue Mar 14, 2017 9:02 pm
by alepap
Very good. Works for a message.

Is it possible to call a function when Cancel is pressed.

Re: Do an action on CANCEL

Posted: Wed Mar 15, 2017 6:12 am
by rdonnay
Is it possible to call a function when Cancel is pressed.
ABORTQUERY was designed to give the programmer the ability to control the exit process of a window.
This is why it requires a code block. Anything can be put into a code block. In the sample I showed you there was only a DCMSGBOX because that's what you said you wanted. You can call any functions that return any values except the last function (expression) must return a logical value. If a .T. is returned then exit will occur, otherwise it will not.

Re: Do an action on CANCEL

Posted: Thu Mar 16, 2017 5:08 am
by alepap
Perfect.

Choo choo !

Re: Do an action on CANCEL

Posted: Thu Mar 16, 2017 6:51 am
by skiman
Hi,

Don't forget that some users hit the ESCAPE key, or click on that nice 'X' in the upper right corner...

See in the dcgetiotions for ABORTQUERY, CLOSEQUERY, EXITQUERY, QUITQUERY

The NOESCAPEKEY clause can also help.