Object 如何使用红色语言从面板访问值
我使用以下代码查找2系列数字的乘积,然后查找这些乘积的和:Object 如何使用红色语言从面板访问值,object,rebol,red,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: fac
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.
]
第一部分工作正常-产品计算正确。但我如何访问这些单独的产品以找到产品的总和?我找不到任何方法,因为这些行实际上不是我可以访问其公共变量或方法/函数的对象。如何解决这个问题?谢谢您的帮助。正如我刚刚了解的面和窗格一样,这里有一个没有错误处理的解决方案
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 ""
]
所有面对象都在父面的窗格块中排序。因此,通过查看单击的face对象的索引,您可以获得一个引用来计算其他face对象的位置 正如我刚刚了解的面和窗格一样,这里有一个没有错误处理的解决方案
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 ""
]
所有面对象都在父面的窗格块中排序。因此,通过查看单击的face对象的索引,您可以获得一个引用来计算其他face对象的位置 在
b/extra:reduce[t1 f1 t2 f2 t3 t4]
中,当您以后只使用其中的3个面引用时,为什么要保存6个面引用?在b/extra:reduce[t1 f1 t2 f2 t3 t4]
中,当您以后只使用其中的3个面引用时,为什么要保存6个面引用?请对其工作原理进行一些解释。Btw@rnso,我注意到您以lispy样式重新设置了缩进和括号的格式。看看这里的红色标准:我不知道红色语言有官方风格。Lispy样式主要节省空间(几乎是空行)。@rnso从外观上看,计算是基于面与单击按钮的接近程度来完成的(请参见行find face/parent/pane face
)。请记住,一旦创建,面仅是以层次方式构造的对象,通常的红色规则适用于此。您可以在这里看到:查看[text”文本窗口中的一些“text”单词“text”按钮“Remove”[Remove face/parent/pane]
请您解释一下它的工作原理。顺便说一下,我注意到您以lispy样式重新格式化了缩进和括号。看看这里的红色标准:我不知道红色语言有官方风格。Lispy样式主要节省空间(几乎是空行)。@rnso从外观上看,计算是基于面与单击按钮的接近程度来完成的(请参见行find face/parent/pane face
)。请记住,一旦创建,面仅是以层次方式构造的对象,通常的红色规则适用于此。您可以在这里看到:查看[文本]在“文本”窗口中的一些“文本”单词“文本”按钮“删除”[删除面/父/窗格]]