Re: widget_problem [message #61510 is a reply to message #61467] |
Thu, 17 July 2008 11:32   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Justus Skorps wrote:
>> Justus
>> stil can not fix it. i have Liam E.Gumley's book but ......
>> Cheers
>> Dave
>
> after u load your arrays (lets call them A) store them with
>
> widget_control, event.top, set_uvalue=A, /nocopy
>
> You have to change 'event.top' that it fits your program...
> In your second button you can now load the arrays with
>
> widget_control, event.top, get_uvalue=A, /nocopy
but don't forget to put them back into your uvalue when you're done!
>
> It is useful to
>
> -store the data in the main widget
> -use a structure to store every data you want
I also tend to use procedures to get the Info state:
; Routine to get the Info state
PRO GetState, ID, Info, No_Copy = No_Copy
; -- Get pointer
WIDGET_CONTROL, ID, GET_UVALUE = InfoPtr
IF ( PTR_VALID( InfoPtr ) EQ 0 ) THEN $
MESSAGE, 'State Information pointer is invalid'
; -- Get state information structure
IF ( N_ELEMENTS( *InfoPtr ) EQ 0 ) THEN $
MESSAGE, 'State information structure is undefined'
IF ( KEYWORD_SET( No_Copy ) ) THEN BEGIN
Info = TEMPORARY( *InfoPtr )
ENDIF ELSE BEGIN
Info = *InfoPtr
ENDELSE
IF ( Info.Debug EQ 1 ) THEN PRINT, 'GetState'
END
and to set the info state
; Routine to set the Info state
PRO SetState, ID, Info, No_Copy = No_Copy
; -- Get pointer
WIDGET_CONTROL, ID, GET_UVALUE = InfoPtr
IF ( PTR_VALID( InfoPtr ) EQ 0 ) THEN $
MESSAGE, 'State information pointer is invalid'
; -- Set state information structure
IF ( N_ELEMENTS( Info ) EQ 0 ) THEN $
MESSAGE, 'State information structure is undefined'
IF ( KEYWORD_SET( No_Copy ) ) THEN BEGIN
*InfoPtr = TEMPORARY( Info )
ENDIF ELSE BEGIN
*InfoPtr = Info
ENDELSE
IF ( (*InfoPtr).Debug EQ 1 ) THEN PRINT, 'SetState'
END
My widget event handlers then do something like:
FUNCTION ComponentTest_LogLin_Event, Event
; -- Get main info state
GetState, Event.Top, Info
; -- Print debug statement if required
IF ( Info.Debug EQ 1 ) THEN PRINT, 'ComponentTest_LogLin_Event'
; -- Set the selected variable number index
Info.LogLin_Index = Event.Value
; -- Save info state
SetState, Event.Top, Info
; -- Display the result
ComponentTest_Display, Event.Top
RETURN, 0
END
Note how I call GetState and then SetState. Because I tend not to use /no_copy, it's
really only an issue when I update a component of the info state (like in my example
above). But, if you *do* use /no_copy, then I think you have to call SetState again to
replace the info pointer.
cheers,
paulv
|
|
|