在此脚本中导致“不绑定到上下文”错误的原因是什么?
题
我有以下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" ]]
]
]
]
.
当我单击第2窗口中的“显示FLD2”按钮以访问FLD2的内容,我正在获得一个生成的icOdeTagcode错误。这是什么原因?以及如何访问第二个窗口内的** Script error: fld2 word is not bound to a context
Word?
解决方案 2
问题是出现的,因为世代odicetagcode函数创建的匿名函数应该是闭包,而不是。查看问题。
其他提示
因为FLD2是匿名功能的本地,而不绑定到用户上下文
>> 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"]]
]
]]]
>>
.
它有效,如果你这样做,那么
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
]
]
. 不隶属于 StackOverflow