2 Replies Last post: Nov 7, 2007 4:45 PM by Tony

A simple question about "at" in the event handling block.

Nov 7, 2007 1:25 AM

Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007
{let cb:CheckButton = {CheckButton label="Tony's Test",

{on ValueChanged at cb1:CheckButton do

|--⑴ {popup-message cb1.value}

|-- ⑵ {popup-message cb.value}

}

}

}

{value cb}



Just as the code, I think ⑴ and ⑵ have the same action, but I always see people use the ⑴ means to handle something. Who can give some guides?
Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
1. Re: A simple question about "at" in the event handling block. Nov 7, 2007 8:57 AM
Tony,

In this case both approaches will work fine, and I don't think there is a strong reason to choose one over the other. But the use of "cb" in the event handler only works because the "let" statement defines the variable cb and binds it to the CheckButton. In some situations, there is no variable that's permanently bound to the button. For example, you might have some code like the following somewhat contrived example:

{HBox
    {CheckButton label="First",
        {on ValueChanged at b:CheckButton do
            {popup-message {format "First is %s", b.value}}
        }
    },
    {CheckButton label="Second",
        {on ValueChanged at b:CheckButton do
            {popup-message {format "Second is %s", b.value}}
        }
    }
}


In this case, the "b" in the "at" clause is the only way to get a name for the CheckButton so its value can be accessed.
Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007
2. Re: A simple question about "at" in the event handling block. Nov 7, 2007 4:45 PM
in response to: rhh
UnderStand! thanks.