Unexpected dialog hang on return

Started by kdmoyers, October 04, 2024, 12:53:09 PM

Previous topic - Next topic

kdmoyers

I'm trying to get a Dialog to exit upon user selecting a row from a reportview.
The following script works fine -- you select a line, then click OK, and it works.

But I wanted to make it exit on the row click itself, so I added the indicated
return(1) statement.  When the program hits that, it hangs.  I have to abort the process.

I can't understand why?!?!?

#definesubroutine MDprocX(DH, DE, DC, undef1, Dextra)
    switch 1
                case DE == @deinit
dialogprocoptions(DH,@dePbPush,1)
dialogprocoptions(DH,@deRvrSelect,1)
retVal = ""
return(@retnoexit)
break
case DE == @deRvrSelect && DC == "nRV"
retVal = Dextra
;return(1) ; enable this line to see bug
break
endswitch
return(@retDefault)
#endsubroutine

arr = arrdimension(1,3)
arr[0,0] = "A"
arr[0,1] = "B"
arr[1,0] = 11
arr[1,1] = 22
arr[2,0] = 1111
arr[2,1] = 2222

MDFormat=`WWWDLGED,6.2`

MDCaption=`GP_Query`
MDX=606
MDY=147
MDWidth=642
MDHeight=222
MDNumControls=004
MDProcedure=`mdprocX`
MDFont=`DEFAULT`
MDTextColor=`DEFAULT`
MDBackground=`DEFAULT,DEFAULT`
MDConfig=0

MD001=`017,191,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
MD002=`081,191,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MD003=`007,025,622,116,REPORTVIEW,"nRV",arr,DEFAULT,DEFAULT,70,@csFirstHeader|@csFullSel,DEFAULT,DEFAULT,DEFAULT`
MD004=`035,009,186,012,STATICTEXT,"StaticText_1",DEFAULT,"click a line in the reportview below",DEFAULT,80,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MD")

message(ButtonPushed,retval)
exit
The mind is everything; What you think, you become.

kdmoyers

((the program was initially much longer and more complex.  This version has the maximum number of lines of code removed while still showing the issue.))
((I'm probably overlooking something really obvious))
The mind is everything; What you think, you become.

td

It is likely caused by the dialog message loop hanging on an internal message sent to the report view control. I will look at it next week. In the interim, you could investigate possible workarounds. For example, use the Win32 PostMessage function to post a WM_QUIT message to the dialog main window instead of using a Return statement
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Your hanging dialog is more the result of a Windows OS bug than a WinBatch bug, but we have a workaround that will be a part of the next release. In the interim, you could test your retVal variable or some flag variable for a value in a timer case of the main switch statement. When the variable is set you simply turn off the timer and issue the return(whatever) statement.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Why a Windows bug?

MSFT documentation states that "The function (i.e., used by WinBatch) also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain."

The key point is that the "flushes the thread message queue" is not always being performed and this is causing the script to hang.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

The mind is everything; What you think, you become.