Use strings to create words and paths in Red language

前端 未结 3 678
春和景丽
春和景丽 2021-01-21 17:21

I have strings in a namelist, that correspond to variables as well as field names in the application.

The function should read strings from namelist, add an

3条回答
  •  粉色の甜心
    2021-01-21 17:58

    This doesn't directly answer your question, though seems to address the problem you're facing. It uses the face/extra field to associate the fields to your value list:

    namelist: [var1 var2]
    var1: 5
    var2: 10
    
    process: function [][
        foreach face lay/pane [
            if find namelist face/extra [
                face/text: form get to word! face/extra
            ]
        ]
    ]
    
    lay: layout [ 
        text "Values to appear here: "
        field "a" extra 'var1
        field "b" extra 'var2
    
        button "Click" [process]
    ]
    
    view lay
    

    The only wrinkles are: it applies get to the words as they are set in the View spec—they need to be within the same context as the values you're working on, and—you can't get a lit-word! so have to change it to word! before getting.

    Another approach if you want to contain your values in a map:

    values: #(foo: 5 bar: 10)
    
    process: function [container [object!]][
        foreach face container/pane [
            if find values face/extra [
                face/text: form select values face/extra
            ]
        ]
    ]
    
    view [ 
        text "Values to appear here: "
        field "a" extra 'foo
        field "b" extra 'bar
    
        button "Click" [process face/parent]
    ]
    

提交回复
热议问题