>>Hi,
>>
>>I wrote (or copied it from somewhere) the code below 10 years ago. And now I don't remember it's purpose. This code is called from the method, right after the READ EVENTS, when application is being closed.
>>What is the purpose of closing all forms when a user wants to close the application?
>>I tried to comment this code and only issue ON SHUTDOWN, after READ EVENTS, and I get no error when some forms are still open. The ON SHUTDOWN seem to close these forms anyways.
>>
>>
>> LOCAL lnForms, i, llDone
>> lnForms = _screen.formcount
>> FOR i = lnForms to 1 STEP -1
>>
>> IF TYPE("_SCREEN.Forms(i)") <> "O" OR ISNULL( _SCREEN.Forms(i) )
>> LOOP
>> ENDIF
>>
>> IF PEMSTATUS(_SCREEN.Forms(i), 'QueryUnload', 5)
>> llDone = _SCREEN.Forms(i).QueryUnload()
>> IF !llDone
>> RETURN .F.
>> ENDIF
>> ENDIF
>> _screen.Forms(i).Release
>> ENDFOR
>>
>>
>>Thank you in advance for any input
>
>If you have a modal form open or a report preview, or a messagebox, this could all be fun. If the forms (objects) get's closed the wrong order you might "close" a form with code waiting for a modal form. The modal one close second, proceeds with the code and you got a lot of strange errors, because THIS and THISFORM, open tables etc the code is expecting are gone. For a long time I even disabled ALT+F4 (ON SHUTDOWN *) etc at all. Now I do a lot of loops and checks to have the forms shutting down in the right order. This might be complex.
Thank you for your input. As I wrote in my message to Dragan, the code above will work in majority of the cases. But since I will include it in a TRY/CATCH, there could be a time when the code will not run. And in this case, the application will try to close with some forms being open.
I will test a case with a messagebox() window being open and at the same time trying to close the application.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham