Quit method question (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: setting clock
Next thread: Blanked out Variables Screen


[OT] How to compile Carbon Shared Library w/ProjectBuilder?   -   Hadley, Joshua
  Quit method question   -   Terry Ford
   Re: Quit method question   -   Thomas Reed
    Re: Quit method question   -   Thomas Reed

Quit method question
Date: 11.12.02 23:37 (Wed, 11 Dec 2002 14:37:36 -0800)
From: Terry Ford
Previously I submitted a question about the Restore operation in
4.5.2. My error was not checking for f.exists in a GetFolderItem that
created a non-existent folderitem and tested for it's nil condition.
Once I understood that it wouldn't show nil, I changed the code to
check for f.exists (instead of f=nil )in an If...Then test and then
give a MsgBox announcement and then quit the application. It worked
perfectly when I entered the code in the open event of the modal
window that I used to open files in the IDE debugger but it showed a
watch cursor. When I built the application and tested it, however,
the message came up with a normal cursor and after the quit command,
I got the message that an ERROR:2 occurred in my built application.
It didn't raise an exception error in the IDE debugger so I changed
the code to self.close instead of quit. Now it showed as a nil object
exception error in the debugger.

I solved this problem by moving the test to the open event of the app
class and that stopped the problem in both the IDE debugger and the
built application.

I have read in some of the NUG responses from RB that MsgBox has some
quirky problems and should only be used for debugging purposes and
NOT in a built application. Could this be the case here as all other
cases of forcing a quit in all of my other windows (via a button
coded for this purpose) works in both the debugger and the built
application.

My question is why when I checked for a folderitem=nil condition it
passed the test but when I checked for a f.exists condition, it
reported a nilobject error?

Re: Quit method question
Date: 12.12.02 16:29 (Thu, 12 Dec 2002 09:29:32 -0600)
From: Thomas Reed
>I solved this problem by moving the test to the open event of the
>app class and that stopped the problem in both the IDE debugger and
>the built application.

That's odd, what you've done is usually a *cause* of problems.
Quitting from an app's Open event (or closing from a window's Open
event) can cause trouble, and is not really advisable.

>I have read in some of the NUG responses from RB that MsgBox has
>some quirky problems and should only be used for debugging purposes
>and NOT in a built application.

Yes, MsgBox is not meant for polished apps. You should design your
own error message window.

What I do is display a custom window using Show (*NOT* ShowModal).
If there's an error that requires quitting in the app's Open event,
this allows the app to go ahead and finish the startup process while
the message is being displayed. When the user closes the error
window, that window calls "Quit". This can be done easily by giving
your error window a "quitOnClose as boolean" property and a method
like the following:

Sub ShowError(msg as string, fatal as boolean)
StaticText1.text = msg

quitOnClose = fatal

Show
End Sub

Then, in the window's Close event, put:

if quitOnClose then
Quit
end if

>My question is why when I checked for a folderitem=nil condition it
>passed the test but when I checked for a f.exists condition, it
>reported a nilobject error?

Can't say without seeing some code, but I'd say you're confused as to
what's causing the NilObjectException, or the FolderItem being
checked for nil isn't the same as the one being checked with the
.Exists property.

Re: Quit method question
Date: 12.12.02 17:57 (Thu, 12 Dec 2002 10:57:31 -0600)
From: Thomas Reed
>I solved this problem by moving the test to the open event of the
>app class and that stopped the problem in both the IDE debugger and
>the built application.

That's odd, what you've done is usually a *cause* of problems.
Quitting from an app's Open event (or closing from a window's Open
event) can cause trouble, and is not really advisable.

>I have read in some of the NUG responses from RB that MsgBox has
>some quirky problems and should only be used for debugging purposes
>and NOT in a built application.

Yes, MsgBox is not meant for polished apps. You should design your
own error message window.

What I do is display a custom window using Show (*NOT* ShowModal).
If there's an error that requires quitting in the app's Open event,
this allows the app to go ahead and finish the startup process while
the message is being displayed. When the user closes the error
window, that window calls "Quit". This can be done easily by giving
your error window a "quitOnClose as boolean" property and a method
like the following:

Sub ShowError(msg as string, fatal as boolean)
StaticText1.text = msg

quitOnClose = fatal

Show
End Sub

Then, in the window's Close event, put:

if quitOnClose then
Quit
end if

>My question is why when I checked for a folderitem=nil condition it
>passed the test but when I checked for a f.exists condition, it
>reported a nilobject error?

Can't say without seeing some code, but I'd say you're confused as to
what's causing the NilObjectException, or the FolderItem being
checked for nil isn't the same as the one being checked with the
.Exists property.

(Sorry if this is a repost, Earthlink was having e-mail trouble
earlier and I don't think these came through...)