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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6<br />

204 Day 6<br />

Rest assured that each property knows what it needs to do to present you with the correct<br />

property editor. You will see different types of property editors as you are <strong>in</strong>troduced to new<br />

components and new properties.<br />

The Events Page<br />

The Events page lists all the events that the property is designed to handle. Us<strong>in</strong>g the Events<br />

page is pretty basic. In order to create an event handler for an event, you simply double-click<br />

<strong>in</strong> the Value column next to the event you want to handle. When you do, <strong>C++</strong>Builder creates<br />

an event-handl<strong>in</strong>g function for you with all the parameters needed to handle that event. The<br />

Code Editor is displayed, and the cursor is placed <strong>in</strong> the event handler. All you have to do<br />

is start typ<strong>in</strong>g code. The name of the function is generated based on the Name property of the<br />

component and the event be<strong>in</strong>g handled. If, for <strong>in</strong>stance, you had a button named OK and<br />

were handl<strong>in</strong>g the OnClick event, the function name generated would be OKClick().<br />

You can let <strong>C++</strong>Builder generate the name of the event-handl<strong>in</strong>g function for you or you can<br />

provide the function name for <strong>C++</strong>Builder to use. To provide the function name yourself,<br />

type the name <strong>in</strong> the Value column next to the event and press Enter. The Code Editor is<br />

displayed, and so is the event-handl<strong>in</strong>g function, complete with the name you supplied.<br />

Once you have created an event-handl<strong>in</strong>g function for a component, you can use that event<br />

handler for any component that handles the same event. Sometimes it’s convenient to have<br />

several buttons use the same OnClick event, for <strong>in</strong>stance. To take it a step further, you might<br />

have a ma<strong>in</strong> menu item, a pop-up menu item, and a speedbar button all use the same OnClick<br />

handler. You will learn to appreciate this k<strong>in</strong>d of code reuse as you ga<strong>in</strong> experience with<br />

<strong>C++</strong>Builder. Even though you are deal<strong>in</strong>g with three different components, they can still<br />

share a common OnClick handler. The Value column of the Events page conta<strong>in</strong>s a dropdown<br />

button that can be used to display a list of all event handlers compatible with the current<br />

event. All you have to do is choose an event from the list.<br />

An MDI Sample Program<br />

To help solidify today’s discussion of projects and forms, let’s create an MDI application.<br />

This application will allow you to open and save graphics files like bitmaps, icons, and<br />

metafiles. In order to complete our task, we’ll have to have a master plan. Here’s what we need<br />

to do:<br />

1. Create the ma<strong>in</strong> w<strong>in</strong>dow form (an MDI parent), <strong>in</strong>clud<strong>in</strong>g a menu.<br />

2. Write code for the File | Open and File | Save menu selections.<br />

3. Write code for the Cascade, Tile, and Arrange All items on the W<strong>in</strong>dow menu.

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

Saved successfully!

Ooh no, something went wrong!