O que está causando um erro “palavra não vinculada ao contexto” neste script?
Pergunta
Eu tenho o seguinte script R3-GUI:
Rebol [
file: %context.reb
]
either exists? %r3-gui.r3 [do %r3-gui.r3][load-gui]
view [
title "First Window"
hgroup [
lab: label "fld 1 "
fld1: field "Field Data 1"
]
button "Display fld 1" on-action [if error? try [probe get-face fld1][alert "Can't read fld1"]]
button "Display fld 2" on-action [if error? try [probe get-face fld2][alert "Can't read fld2"]]
button "Open 2nd Window" on-action [
view [
title "Second Window"
hgroup [
label "fld 2" fld2: field "field 2 data"
]
button "Display fld1" on-action [if error? err: try [probe get-face fld1][probe err alert "Can't read fld1"]]
button "Display fld2" on-action [if error? err: try [probe get-face fld2][probe err alert "Can't read fld2" ]]
]
]
]
Quando clico no botão "Exibir fld2" na 2ª janela para acessar o conteúdo do fld2, estou recebendo uma mensagem ** Script error: fld2 word is not bound to a context
erro.Qual é a causa disso?E como faço para acessar o fld2
palavra dentro da segunda janela?
Solução 2
O problema surge porque a função anônima que está sendo criada pelo parse-layout
function deveria ser um encerramento, e não é.Veja a diferença em https://gist.github.com/earl/a009454787d9fe4cfaca o que resolve o problema.
Outras dicas
porque fld2 é local para uma função anônima e não está vinculado ao contexto do usuário
>> help win-face/facets/tab-face/actors
WIN-FACE/FACETS/TAB-FACE/ACTORS is a block of value: [on-action make function! [[face arg
/local fld2 err
][
view layout [
title "Second Window"
hgroup [
label "fld 2" fld2: field "field 2 data"
]
button "Display fld 1" on-action [if error? try [probe get-face fld1] [alert "Can't read fld1"]]
button "Display fld2" on-action [if error? err: try [probe get-face fld2] [probe err alert "Can't read fld2"]]
]
]]]
>>
funciona, se você fizer assim
l2: layout [
title "Second Window"
hgroup [
label "fld 2" fld2: field "field 2 data"
]
button "Display fld1" on-action [if error? err: try [probe get-face fld1][probe err alert "Can't read fld1"]]
button "Display fld2" on-action [if error? err: try [probe get-face fld2][probe err alert "Can't read fld2" ]]
]
view l1: layout [
title "First Window"
hgroup [
lab: label "fld 1 "
fld1: field "Field Data 1"
]
button "Display fld 1" on-action [if error? try [probe get-face fld1][alert "Can't read fld1"]]
button "Display fld 2" on-action [if error? try [probe get-face fld2][alert "Can't read fld2"]]
button "Open 2nd Window" on-action [
view l2
]
]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow