WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.X
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Cancel Handler Issues within Dialogs

 Keywords: dialog callback procedure cancel button ask askline udf uds user defined 

Question:

Problem: The cancel handler seems messed up when a cancel event occurs due to an Ask*()-type function from inside of the callback subroutine. This sample script is a simplified version of an actual chunk of the software delivery system I'm writing.

Here is my code:

-------------------------------
; Create dynamic dialog constants.
evtInit       = 0
evtButton     = 2
; Set CANCEL handler to use GOSUB.
IntControl(72, 2, 0, 0, 0)

#DefineSubroutine foobat(dlgHandle, dlgEvent, dlgControl, dlgRsrvd1, dlgRsrvd2)
If (dlgEvent == evtInit)
	DialogProcOptions(dlgHandle, evtButton, 1)
EndIf
If (dlgEvent == evtButton)
	foo()
EndIf
Return -2
#EndSubroutine
#DefineSubroutine foo()
while 1
	bat = askline("foo", "bat", "")
	If isdefined(bat) Then break
endwhile
Return
#EndSubroutine
MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=201
MyDialogY=125
MyDialogWidth=210
MyDialogHeight=144
MyDialogNumControls=001
MyDialogProcedure=`foobat`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`

MyDialog001=`079,093,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")
Exit
-------------------------------

Here is my cancel handler:
-------------------------------
:CANCEL
IntControl(72, 2, 0, 0, 0)
Drop(bat)
Return
-------------------------------
If I place the handler in the main part of the script, when the cancel button is pressed during the AskLine() function, the label is entered and the following variables are created:
wberrorhandlerline = ButtonPushed=Dialog("MyDialog")
wberrorhandlerassignment = bat
wberrorhandleroffset = 108
When the RETURN from my cancel label is hit, the script breaks out of the dialog altogether and proceeds to the command following the ButtonPushed assignment (which is Exit), despite the fact that I'm supposed to be nested inside of two other subroutines at the time.

When I place the cancel handler inside the foo() subroutine, where the Cancel event actually happens, the label is jumped to and the following variables are created:

wberrorhandlerline = bat = askline("foo", "bat", "")
wberrorhandlerassignment = bat
wberrorhandleroffset = 11
And the script returns to the line following the call to the foo() subroutine in the callback subroutine (which is EndIf).

In either case, as a WinBatch programmer I assumed that the script would return to the line immediately following the AskLine() function. This didn't happen in either case, which is very confusing to me. The foo() subroutine just seems to get dumped whenever a cancel event happens from inside of it.

Answer:

1) Very confusing combo problem.

2) Partly related to the problem you reported previously where a :CANCEL label in a #DefineSubroutine is not totally invisible to an outside cancel handler. This helps make it really confusing. Then if you want to capture a cancel inside a function or subroutine, it needs its own cancel handler and its own IntControl 72.

Test with #DefineFunctions until the #DefineSubroutine problem gets cleared up.

;-------------------------------
; Create dynamic dialog constants.
evtInit       = 0
evtButton     = 2
; Set CANCEL handler to use GOSUB.
IntControl(72, 2, 0, 0, 0)

#DefineSubroutine foobat(dlgHandle, dlgEvent, dlgControl, dlgRsrvd1, dlgRsrvd2)
If (dlgEvent == evtInit)
	DialogProcOptions(dlgHandle, evtButton, 1)
EndIf
If (dlgEvent == evtButton)
   switch dlgcontrol
      case 1  ; OK
      	foo()
         Pause("","In foobat OK")
         return(-2)
      case 2  ; cancel
         Pause("","in foobat Cancel")
         return 0
    endswitch
EndIf
Return -2
#EndSubroutine


#DefineSubroutine foo()
IntControl(72, 2, 0, 0, 0)
while 1
	bat = askline("foo", "bat", "")
   Pause("","In foo")
	If isdefined(bat) Then break
endwhile
Return
:CANCEL
IntControl(72, 2, 0, 0, 0)
Message("Cancel","in foo handler")
Drop(bat)
Return
#EndSubroutine


MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=201
MyDialogY=125
MyDialogWidth=210
MyDialogHeight=144
MyDialogNumControls=002
MyDialogProcedure=`foobat`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`

MyDialog001=`079,093,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`90,40,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")
Message("","After Dialog")
Exit
-------------------------------

Here is my cancel handler:
-------------------------------
:CANCEL
IntControl(72, 2, 0, 0, 0)
Message("Cancel","in main handler")
Drop(bat)
Return

Article ID:   W15124
File Created: 2002:09:05:13:49:50
Last Updated: 2002:09:05:13:49:50