Do an action on CANCEL

If you are converting a text-based Clipper application, a FoxPro application or just writing an application from scratch, use this forum for your eXpress++ questions.
Post Reply
Message
Author
User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Do an action on CANCEL

#1 Post 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 ***

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Do an action on CANCEL

#2 Post 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}
The eXpress train is coming - and it has more cars.

User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Re: Do an action on CANCEL

#3 Post by alepap »

Very good. Works for a message.

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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Do an action on CANCEL

#4 Post 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.
The eXpress train is coming - and it has more cars.

User avatar
alepap
Posts: 94
Joined: Tue Jul 28, 2015 5:15 am

Re: Do an action on CANCEL

#5 Post by alepap »

Perfect.

Choo choo !

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Do an action on CANCEL

#6 Post 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.
Best regards,

Chris.
www.aboservice.be

Post Reply