Re: Problem with pointers to structures [message #38657] |
Wed, 17 March 2004 23:39 |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Tianle Yuan wrote:
> This bothers me for quite a while and I still can't figure out why it
>
> doesn't work.
>
> Pro A
> .
> .
> str = {f1:..,f2:..,...}
> str_ptr = ptr_new(str)
> .
> .
> widget_control,...,set_uvalue = str_ptr
> .
> .
> end
>
> Pro A_sub,event
> .
> widget_control,...,get_uvalue= str_ptr
> temp = *str_ptr
> temp.f1 = ...
>
> end
>
> When I excute it, it says 'expression must be a structure in this
>
> context:temp'. But according to Gumley's book, this should work fine.
>
> Any comments?
>
> -TL
>
You did not have said what you like to put on temp.f1
IDL> str={f1:1,f2:2}
IDL> ptr=ptr_new(str)
IDL> temp=*ptr
IDL> help,temp,/str
** Structure <82e79ec>, 2 tags, length=4, data length=4, refs=3:
F1 INT 1
F2 INT 2
IDL> temp.f1=10
IDL> PTR_FREE,ptr
Please try this! Does this work?
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-I)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
------------------------------------------------------------ -------
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
============================================================ =======
|
|
|
Re: Problem with pointers to structures [message #38662 is a reply to message #38657] |
Wed, 17 March 2004 14:51  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
"Tianle Yuan" <tianle@rac3.wam.umd.edu> wrote in message
news:c3aho3$8fj$1@grapevine.wam.umd.edu...
> This bothers me for quite a while and I still can't figure out why it
doesn't work.
>
> Pro A
> .
> .
> str = {f1:..,f2:..,...}
> str_ptr = ptr_new(str)
> .
> .
> widget_control,...,set_uvalue = str_ptr
> .
> .
> end
>
> Pro A_sub,event
> .
> widget_control,...,get_uvalue= str_ptr
> temp = *str_ptr
> temp.f1 = ...
>
> end
>
> When I excute it, it says 'expression must be a structure in this
> context:temp'. But according to Gumley's book, this should work fine.
> Any comments?
When implemented correctly, as shown in the example programs in the book
(e.g., wgetname.pro and wpaint.pro in Chapter 9), this technique works just
fine.
If this technique does not work in your code, I suspect there is something
wrong with your code. However, you have not provided enough of your code for
inspection. You might want to try shortening your program to the minimum
number of lines that reproduces the error. This process may well fix the bug
in your code. Otherwise, post the entire program in your next message.
Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
|
|
|