[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error on shutdown of widget !@$%



Sean Heukels (sean77=cuthere=@dds.nl) writes:
 
> How do I get rid off, or catch this error ??
> 
> When I shutdown my widget program by clciking exit, in my menubar, I can
> reset colors, structures, the whole thing.
> But when I click the Top-right-cross (Windows) And top-left=box on Unix,
> which shutsdown the current process, I get an error by widget_event,
> that this one ('named by number') is not defined.
> 
> I wish to clean up the variables that I clean on pushing exit in the same
> way and dont want 2 create errors.
> 
> How can this be done ??

While it *sounds* like a good idea to put all
your cleanup in the Exit button event handler,
it never works, as you have discovered, because
nobody uses it. They kill widgets with the 
mouse, not by clicking the Exit button.

So, take *all* your cleanup out of the Exit button
event handler and put it in a CLEANUP routine
associated with the top-level base widget by means
of a CLEANUP keyword on the XMANAGER command.
Make a *SEPARATE* event handler for your Exit
button that does nothing but destroy the TLB.

I say *SEPARATE* because your other problem, I'm
sure, stems from having all your event handler
code in the same procedure. The error you 
get on exit is because you are trying to do 
something with the top-level base after you 
just killed it! (90% of the time people are
trying to put something into the user value of
the top-level base after they just killed it.)

While people who know what they are doing
(Stein Vidar comes to mind) can write code
with one huge event handler, I've never known
it to be anything but totally confusing for
people just getting started with IDL. You will
have a lot more luck writing widget programs
with lots of separate event handlers, but this 
is especially true for your exit button.

If you are looking for examples, you can try
any of the widget programs on my web page. 

And, although it sounds like a hell of a lot
of money, getting a good book to show you
the proper way of writing widget programs
saves an enormous amount of wear and tear,
not to mention frustration. :-)

Cheers,

David

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155