12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

VCL Components<br />

The GroupIndex Property<br />

Speed buttons can be grouped to make them behave like radio buttons (radio buttons are<br />

discussed later <strong>in</strong> the chapter <strong>in</strong> the section “Radio Buttons and Check Boxes”). When one<br />

button <strong>in</strong> the group is pressed, it stays down, and the button that was previously pressed pops<br />

up aga<strong>in</strong>. To group speed buttons, simply assign the same value to the GroupIndex property<br />

for all buttons <strong>in</strong> a group. (The default value of 0 <strong>in</strong>dicates that the button is not part of any<br />

group.) To illustrate, do the follow<strong>in</strong>g exercise:<br />

1. Create a blank form and place five speed buttons on the form. (I won’t bother with<br />

add<strong>in</strong>g glyphs to the buttons <strong>in</strong> this simple exercise, but you certa<strong>in</strong>ly may if you<br />

want.)<br />

2. Select all the buttons and change the value of the GroupIndex property to 1. The<br />

GroupIndex for all buttons will be changed to 1.<br />

3. Optional: Change the Down property of one of the buttons to true.<br />

4. Click the Run button to compile and run the program.<br />

When you run the program, click on several of the buttons. You will notice that only one<br />

button can be <strong>in</strong> the down state at one time. As you can see when you assign a nonzero value<br />

to GroupIndex, the speed buttons change their behavior. A speed button with a GroupIndex<br />

of 0 pops back up when you click it, whereas a speed button that is part of a group stays down<br />

when clicked.<br />

The AllowAllUp Property<br />

By default, one button <strong>in</strong> the group must be down at all times. You can change that behavior<br />

by sett<strong>in</strong>g the AllowAllUp property to true. Do<strong>in</strong>g this for one button automatically changes<br />

the AllowAllUp property for all other buttons <strong>in</strong> the group to true as well. Now you can have<br />

any one button <strong>in</strong> the group selected or no buttons at all.<br />

TIP<br />

Sometimes you want a speed button to act as a toggle button. A toggle<br />

button is used to turn an option on or off and is not part of a button<br />

group. To make an <strong>in</strong>dividual speed button a toggle button, assign a<br />

nonzero value to its GroupIndex property and set its AllowAllUp property<br />

to true. Be sure to set the GroupIndex property to a value not used by any<br />

other components on the form. When the user clicks the button, it stays<br />

down. When the button is clicked aga<strong>in</strong>, it pops back up.<br />

303<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!