Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Releasing forms programmatically
Message
From
20/12/2022 07:04:07
 
 
To
19/12/2022 13:51:59
Lutz Scheffler (Online)
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01685522
Message ID:
01685532
Views:
58
>>In a complex application, we've set up a timeout (based on the code I published here: http://www.tomorrowssolutionsllc.com/Articles/Taking%20Advantage%20of%20Idle%20Cycles.PDF) that shuts down the application if the user does nothing (no keystrokes, no mouse movements) within a specified time. It works well, except in one situation.
>>
>>If the user has stopped with a modal form open on top of another modal form on top of a modeless form, the code to close all the forms fails. Here's the code:
>>
>>
>>FOR lnForm = 1 TO _screen.FormCount
>>   TRY 
>>      loForm = _screen.Forms[1]
>>   CATCH 
>>      loForm = .null.
>>   ENDTRY 
>>   
>>   IF NOT ISNULL(m.loForm)
>>      *-- TEG 8/6/2020 
>>      * Wrap in TRY-CATCH in case of problems
>>      TRY 
>>         loForm.Release()
>>      CATCH TO loException
>>         do LogError with "Form " + loForm.Name + " (" + loForm.Caption + ") wouldn't closed", ;
>>                          loException.Message, "", .t., .t., .t.
>>         llProceed = .F.
>>      ENDTRY 
>>      
>>      IF NOT m.llProceed
>>         EXIT 
>>      ENDIF 
>>   ENDIF 
>>ENDFOR 
>>
>>
>>What happens is that the modal form on top closes, but the one below it doesn't. When its Release method is called, nothing happens--no events fire. That same form remains first in the Forms collection, so we spend the remaining passes through the loop just trying to release that form.
>>
>>If we have a single modal form open over a non-modal form, all is well and things shut down as expected. I don't think this application has any cases where we can have a modal form over a modal form without a non-modal form underneath, so I can't test that.
>>
>>I'm pretty sure the issue has to do with the code the modal form leaves "hanging." That is, in this application, pretty much every modal form is called as a function and there's a same-named program that sets things up and runs the modal form. I think I need to find some way to end that code as well, but I'm blanking on how to do that.
>>
>>Any suggestions?
>>
>>Tamar
>
>Tamar,
>I must admit it's a bit to complex to describe. There is a sort of cascading the forms down and stop closing if a child is modal.
>Like
>Form A opens form B modal in method A.Show_Modal. This method sets a property to tell A it keeps a modal form open.
>
>Now some handler in the application (we call it QuitApp) knows about form A and tries A.QueryUnload (We note: A.Show_Modal is still running)
>A.QueryUnload see it keeps a modal form and remarks it can not unload
>A.QueryUnload calls B to close
>A.QueryUnload returns .F.
>
> This forces B to close, then A.Show_Modal to end and end all in the callstack
>
>The application.QuitApp has received the False from A.QueryUnload. It starts a timer (around a second to run all the code, this is guesswork) , closes itself.
>Now the timer restarts application.QuitApp,this recalls A.QueryUnload and since B is no longer active can return True.
>
>If set accordingly, you can run a chain of modal forms by returning false down the row, rerun the timer every time.
>
>Conclusion: The trick is to end A.QueryUnload and rerun a little bit later, so A.Show_Modal can end.
>
>There is more involved. I spend a month or so to keep it running.
>
>If you need the code, I can look if I can isolate the form class and the application class

Thanks. Sounds like a similar situation. I'll see whether a similar solution will help.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform