How to set a variable in a Rebol 3 view and use the value after the window closes?

StackOverflow https://stackoverflow.com/questions/17797150

  •  03-06-2022
  •  | 
  •  

Pregunta

I want to set a variable in a Rebol 3 button handler (GUI) and use the value after the window is closed. How do I get the value outside of the view block? Here is an example code:

view [
    v_username:  field
    button "Submit" on-action [
        username: get-face v_username 
        close-window face
    ]
]

probe username

The result is "" regardless of the content of v_username.

Does it have to be 'declared' as a global variable? Should I get this value from a returned value of the view?

¿Fue útil?

Solución

The 'on-action block when invoked is wrapped in a function (Rebol function where set-words are assumed local to the function). You have a couple of options to work around this:

  1. Use an object to store the values in (set-paths are not bound within function):

    values: context [username: none]
    view [... on-action [values/username: get-face ...]]
    
  2. Use 'set to set the word. I find this a little less reliable as it's uncertain the context of the word you are setting:

    view [... on-action [set 'username get-face ...]]
    
  3. Though perhaps the best option is to keep in mind that the words you assign to styles are bound the context you're working in, so:

    view [username-field: field ...]
    username: get-face username-field
    
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top