首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是什么导致了这个脚本中的“不绑定到上下文的单词”错误?

是什么导致了这个脚本中的“不绑定到上下文的单词”错误?
EN

Stack Overflow用户
提问于 2014-04-13 06:25:39
回答 2查看 170关注 0票数 1

我有以下R3-GUI脚本:

代码语言:javascript
复制
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" ]]
        ]
    ]
]

当我点击第二个窗口中的“Displayfld2”按钮来访问fld2的内容时,我将得到一个** Script error: fld2 word is not bound to a context错误。原因是什么?以及如何访问第二个窗口中的fld2单词?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-14 07:06:54

问题的出现是因为由parse-layout函数创建的匿名函数应该是闭包,而不是闭包。请参见https://gist.github.com/earl/a009454787d9fe4cfaca的差异,它解决了这个问题。

票数 1
EN

Stack Overflow用户

发布于 2014-04-13 14:10:23

因为fld2是匿名函数的本地函数,而不绑定到用户上下文。

代码语言:javascript
复制
>> 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"]]
        ]
    ]]]
>>

如果你这样做的话,它会起作用的

代码语言:javascript
复制
 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
   ]
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23039878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档