如何使用红色语言

时间:2017-09-18 08:33:17

标签: object rebol red

我使用以下代码查找2系列数字的产品,然后找到这些产品的总和:

  make-row: func [][
    compose [
        t1: text "N1:"
        f1: field 
        t2: text "N2: "
        f2: field
        t3: text "Product: "
        t4: text ""
        b: button "Get product" [
            x: face/extra/2/text          
            y: face/extra/4/text
            z: (to-integer x) * (to-integer y)
            face/extra/6/text: rejoin [z]]
        do [b/extra: reduce [t1 f1 t2 f2 t3 t4]] ]  ]

  view compose [
        (make-row) return 
        (make-row) return
    b: button "Calculate" [t2/text: "..to be given"]
    t1: text "Sum of products:"
    t2: text ""                       ; NEED TO GET SUM OF ALL PRODUCTS IN ABOVE ROWS. 
  ]  

第一部分正常工作 - 正确计算产品。但是,如何才能访问这些单独的产品以查找产品总数?我找不到任何方法,因为行不是真正的对象,我可以访问其公共变量或方法/函数。怎么解决这个问题?谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

正如我刚刚了解到面孔和窗格,这里是一个没有错误处理的解决方案

make-row: func [][
     compose [
        text "N1:"
        field 
        text "N2: "
        field
        text "Product: "
        text ""
        button "Get product" [
            b1: index? find face/parent/pane  face
            face/parent/pane/(b1 - 1)/text:  form multiply   to-integer   face/parent/pane/(b1 - 5)/text  to-integer face/parent/pane/(b1 - 3)/text  
        ]

    ]  
]
view compose [
    (make-row) return 
    (make-row) return
    button "Calculate" [
        t2/text:   form add to-integer face/parent/pane/6/text  to-integer face/parent/pane/13/text
    ]
    text "Sum of products:"
    t2: text ""  
]   

所有面部对象都在父面部的窗格块中排序。因此,查看单击的面对象的索引,可以获得计算其他面对象位置的引用。