Home   Archive   Permalink



'inform' inside a function

For a little project, and also for my education, I want to make a function to which I can pass a block of stuff and have it pop up a window with a text-list of that stuff, and then return what is picked from the text-list. An abbreviated sample is shown below. It does not seem to return what is picked (or "none" if nothing is picked), but instead returns some REBOL source code. I include a test function, GET-EMAIL-X, to show that my calling methodology is correct, so the problem must be in my use of the "inform" function inside of a function. I wonder if this can be done, or if I am doing something wrong.
    
Thank you.
    
R E B O L []
    
;; This is what I want to do but it does not return the right result.
GET-EMAIL: func [
     EMAIL-LIST
     /local PARSED-EMAIL
] [
     inform ADDR-LIST: layout [
         ADDRS: text-list 300x400 data EMAIL-LIST [
             PARSED-EMAIL: first ADDRS/picked ":"
             hide-popup ADDR-LIST
             return PARSED-EMAIL
         ]
         button "Close" [
             hide-popup ADDR-LIST
             return none
         ]
     ]
]
    
;; This shows the test code is correct because it does return a result.
GET-EMAIL-X: func [
     EMAIL-LIST
] [
     return first EMAIL-LIST
;; return none
]
    
;;Uncomment to test
;RESULT: GET-EMAIL-X [ ;; This does what is expected.
RESULT: GET-EMAIL [ ;; RESULT will have some sort of source code.
     "adam@gmail.com"
     "benjamin@gmail.com"
]
print "probe RESULT to see what happens."
halt

posted by:   Steven White       23-Oct-2018/16:58:01-7:00



'request-list does that:
    
request-list "Pick an email" ["adam@gmail.com" "benjamin@gmail.com"]
    
If you 'source request-list', you can see how the return values are managed and customize the function as needed:
    
request-list: func [
     "Requests a selection from a list."
     titl [string!]
     alist [block!] /offset xy /local rslt list-lay
][
     list-lay: layout [
         origin 10x10
         h3 titl
         text-list data alist [rslt: value hide-popup]
         btn-cancel #"^[" [rslt: none hide-popup]
     ]
     rslt: none
     either offset [inform/offset list-lay xy] [inform list-lay]
     rslt
]
    
I don't want to harp on it, but I think it's important to point out that all this can be gotten without any third party documentation.

posted by:   Nick       24-Oct-2018/11:07:23-7:00



Well, then, there is a head-slapping moment. Regarding that concept of third-party documentation, some time ago, frustrated by the lack of documentation for VID, I wrote my own third-party documentation. Not that VID was undocumented, but the documentation that I could find was not organized to my liking for a reference manual.
    
So after reading your above note, I went to MY OWN documentation, and THERE IS WAS, a section on request-list.    
    
What more can a guy do...

posted by:   Steven White       24-Oct-2018/14:51:12-7:00



Name:


Message:


Type the reverse of this captcha text: "? e v i t a n"



Home