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.

Work<strong>in</strong>g with the Form Designer and the Menu Designer<br />

Writ<strong>in</strong>g the Code<br />

Okay, so we have all these menu items but no code to make them work. It’s go<strong>in</strong>g to be a lot<br />

of work to implement all these menu items, right? Actually, it’s pretty easy. Most of the code<br />

required is already part of the TMemo class. All we have to do is call the appropriate TMemo<br />

methods <strong>in</strong> our menu handlers. We’ll have to do a few other th<strong>in</strong>gs, but most of what we will<br />

add is code you have seen before.<br />

Before we write the code, we need to add the usual OpenDialog and SaveDialog components<br />

to the form:<br />

1. Place an OpenDialog component on the form.<br />

2. Change the Name property to OpenDialog.<br />

3. Place a SaveDialog component on the form.<br />

4. Change the Name property to SaveDialog.<br />

5. L<strong>in</strong>e up the Ma<strong>in</strong>Menu, OpenDialog, and SaveDialog icons on the form.<br />

That was easy enough. Now let’s get on with writ<strong>in</strong>g the code for the menu items. We’ll start<br />

with the File Exit menu item (hey, it’s the easiest!). Be sure that the Menu Designer is closed<br />

so you don’t confuse the Menu Designer with the Form Designer.<br />

1. Choose File | Exit from the ma<strong>in</strong> menu. The Code Editor comes to the top, and<br />

the FileExitClick() event handler is displayed.<br />

2. The cursor is positioned and ready to go. Type the follow<strong>in</strong>g at the cursor:<br />

NOTE<br />

Close();<br />

In step 2 I had you use the Close() function to close the form. This<br />

works f<strong>in</strong>e here because this is the ma<strong>in</strong> form of the application. But if<br />

you want to term<strong>in</strong>ate the application from anywhere <strong>in</strong> the program<br />

you should use this:<br />

Application->Term<strong>in</strong>ate();<br />

This will ensure that the application is term<strong>in</strong>ated regardless of which<br />

form is currently open.<br />

That’s it. I told you it was the easiest! Let’s do one more; then I’m go<strong>in</strong>g to turn you loose<br />

to f<strong>in</strong>ish the rest on your own.<br />

253<br />

7

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

Saved successfully!

Ooh no, something went wrong!