The following code uses procedures with the Button component as parameter. A similar technique can be used with other components.
Note: