1

我正在使用以下代码尝试从函数中获取 GUI 元素:

  mypanelfn: func[] [
    collect[
      repeat i 10 [ 
        print append copy "i in loop: " i
        keep [t: text]  keep append copy "message: " i
        keep [field "entry"    
              button "Click" [t/text: "clicked"] return]]]]

  view [ 
    do [mypanelfn]]

没有错误消息并且循环正常进行并且还显示一个窗口。但这只是一个没有任何文本、字段或按钮的小空窗口。

这段代码有什么问题?

编辑:在节目probe之前放置collect(为了清楚起见,我添加了换行符):

[t: text "message: 1" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 2" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 3" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 4" field "entry" button "Click" [t/text: "clicked"] return 
t: text "message: 5" field "entry" button "Click" [t/text: "clicked"] return
4

4 回答 4

3

这个方法不需要设置任何变量——它通过在一个共同的父对象中包含每个面的迭代来工作(panel):

view collect [
    keep [below space 0x0]
    repeat i 10 [
        keep compose/deep [
            panel [
                origin 0x0
                text (rejoin ["Message Number: " i])
                field "entry"
                button "Click" [face/parent/pane/1/text: "clicked"]
            ]
        ]
    ]
]

face/parentpanel第一个孩子 ( pane/1) 是文本框的人脸(origin不创建人脸)。

于 2017-09-17T21:55:44.953 回答
2

但是,您不一定需要那里的功能:

view mypanelfn

作品。

注意:Rebol 中的等效代码需要layoutview layout mypanelfn

发生这种情况的原因是因为view进程blocks!(里面的任何东西[])。所以你不必这样做do

一般来说,最好将 Red 视为一种功能性的消息传递语言。与具有过程和语句的命令式语言相比,一切都是表达式。

于 2017-09-17T08:31:36.160 回答
1

这在 rebol/view 中对我有用:

lay: mypanelfn
insert head lay 'across
view layout lay

在此处输入图像描述

我认为,当您学习这些内容时,您需要查看生成的 VID 代码以检查是否没有问题,然后再尝试查看它。

于 2017-09-17T08:24:21.433 回答
1

再次; 您需要为要处理的元素提供唯一名称。这是一个使用reduce而不是compose的解决方案

mypanelfn: func[] [
  collect[
    repeat i 10 [ 
      tname: to-word rejoin ['t i]
      print append copy "i in loop: " i
      keep  reduce [to-set-word tname 'text]  keep append copy "message: " i
      keep reduce [
       'field "entry" 'button "Click"  reduce  [ 
          to-set-path  reduce [
             tname 'text ]
            "clicked" ]
      'return ] ] ] ] 

我建议您使用控制台中的命令来查看它们的作用。例如

rejoin ['t i]"t1"用 t 和 i 的 (reduced/get-) 值创建一个字符串。

to-word将其更改为 Red(bol) 字t1

to-setword tname 创建一个固定词t1:

to-set-path reduce [tname 'text ]创建一个设置路径 t1/text:

于 2017-09-17T10:29:36.993 回答