[Next] [Previous] [Up] [Top] [Contents] [Index]

Views and subviews

Adding a button

Notice that a button has been added to the window, with the specified text. When you press the mouse on the button, the button highlights, and tracks the mouse movement appropriately. When you release the button, the action is run.

In this case, the action is an anonymous function. That's the meaning of the expression beginning with "#'(lambda...". The lambda expression creates a function of one argument, self, it ignores that argument, and it then calls the function beep. The anonymous function is stored as the action-function of the dialog item. It is called when the button is clicked.

When a button's action-function is called, the button itself is passed as an argument. That way the function can find out what dialog it is in, etc. In this case, we do not need to use that information. That's why we declare that we are ignoring the argument. If the lambda expression did not include that declaration, the compiler would issue a warning about an unused argument.


Gettmg Started with MCL - 19 OCT 1996
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker