Re: Common block conumdrum [message #8440 is a reply to message #8355] |
Tue, 04 March 1997 00:00   |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Daniel Williams wrote:
>
> When developing programs in IDL, I often work with common blocks.
> However, if I try to change the definition of an existing common
> block, I get an error because it IDL thinks that I am trying to use a
> pre-existing common block in a naughty manner. According to the
> user's manual (v3.6 p6-10) this is what IDL should do.
> However, when creating new programs, I often want to change the
> definition of the common block as the program developes. How can I do
> this, short of exiting IDL and starting over? Is there some "delvar"
> equivalent for deleting common blocks or programs from memory?
There are times when common blocks are very useful, such as when
you must share data between various programs. If you are using
common blocks so that you have "global" variables within a single
application, I would strongly suggest that you follow the example
presented in the User's Guide, Ch. 21 "Writing a Compound Widget",
and store the "state" information in the uvalue of the first
child of your main base. Then, in the event handler you can use:
stash = WIDGET_INFO( event.top, /child )
WIDGET_CONTROL, stash, get_uvalue = state, /no_copy
to retrieve this state structure. Then pass the structure to your
routines. See the example above for details.
This method is a little bit slower, but a lot cleaner and safer
(you don't have to worry about using "reserved" variable names and
overwriting something in the common block, for example).
If you really need a common block, then the suggestion by Phil
Williams to use a large structure as your first variable in the
common block is a good one; you can add tags to this structure as
you need them. This also avoids the problem of inadvertently re-using
common-block variables.
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2200
La Jolla, CA 92037
[ UCSD Mail Code 0949 ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|