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.

152 Day 5<br />

Figure 5.4.<br />

The form with all<br />

components added.<br />

What we have done here is create a s<strong>in</strong>gle event-handl<strong>in</strong>g function that handles the OnClick<br />

event of both buttons. We use the Sender parameter to determ<strong>in</strong>e which of the two buttons<br />

sent the OnClick event and then either hide or show the memo component as needed. We<br />

could have created a separate OnClick handler for each button, but with this method the code<br />

is a little more compact. Besides, it’s a good illustration of how Sender can be used.<br />

You can see from this exercise that once you have created an OnClick event handler for a<br />

particular component, you can attach that same handler to the OnClick event of any<br />

component on the form. I’ll discuss more of the details of events as we move through the<br />

book.<br />

HOUSE RULES: EVENTS<br />

■ You may respond to any of a component’s events as needed.<br />

■ You are not required to respond to all events a component def<strong>in</strong>es.<br />

■ Events are handled by event-handl<strong>in</strong>g functions called event handlers.<br />

■ Several components may share a common event handler.<br />

■ Event handler names produced by <strong>C++</strong>Builder are default names and may be<br />

changed by the programmer.<br />

■ Be sure to change an event handler’s name only <strong>in</strong> the Object Inspector.<br />

■ The Sender parameter of an event handler can be used to determ<strong>in</strong>e which<br />

component fired the event.

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

Saved successfully!

Ooh no, something went wrong!