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.

364 Day 10<br />

At the top of the Forms page is the Ma<strong>in</strong> form combo box. This is where you tell <strong>C++</strong>Builder<br />

which form to display when the application starts. By default, the first form you create will<br />

be the ma<strong>in</strong> form. If you change your project <strong>in</strong> such a way that a different form becomes the<br />

ma<strong>in</strong> form, you will need to change this sett<strong>in</strong>g so that the new form becomes the<br />

application’s ma<strong>in</strong> form.<br />

In the middle of the dialog box, you see two list boxes. The list box on the left is labeled Autocreate<br />

forms; the one on the right is labeled Available forms. Before I talk about how to use<br />

these two list boxes, let’s take a moment to talk about auto-creation of forms.<br />

Each time you create a form, <strong>C++</strong>Builder places that form <strong>in</strong> the auto-create list for the<br />

application. Auto-creation means that <strong>C++</strong>Builder will construct the form dur<strong>in</strong>g the<br />

application startup process. Forms that are auto-created will display more quickly than forms<br />

that are not auto-created. The disadvantage to auto-creation of forms is that your application<br />

will use more memory than it would if your forms were not auto-created. Another<br />

disadvantage, although probably <strong>in</strong>significant, is that your application will take slightly<br />

longer to load if you are auto-creat<strong>in</strong>g a lot of forms.<br />

NOTE<br />

The first form <strong>in</strong> the Auto-create forms list box is always the ma<strong>in</strong><br />

form. If you change the ma<strong>in</strong> form, the new form selected will move to<br />

the top of the Auto-create forms list box. Another way to set the ma<strong>in</strong><br />

form is to drag-and-drop any one of the forms <strong>in</strong> the Auto-create forms<br />

list box to the top of the list.<br />

The nice th<strong>in</strong>g about auto-creation is that display<strong>in</strong>g an auto-created form is easy. All you<br />

have to do is call that form’s Show() or ShowModal() function:<br />

AboutBox->ShowModal();<br />

If you do not have your forms auto-created by <strong>C++</strong>Builder, you will have to take the<br />

responsibility of creat<strong>in</strong>g the form before you use it:<br />

TAboutBox* aboutBox = new TAboutBox(this);<br />

aboutBox->ShowModal();<br />

delete aboutBox;<br />

This example does not use the <strong>C++</strong>Builder-generated po<strong>in</strong>ter to the About box. It creates a<br />

local po<strong>in</strong>ter, displays the form, and then deletes the po<strong>in</strong>ter as soon as the form is no longer<br />

needed. As is often the case <strong>in</strong> <strong>C++</strong> programm<strong>in</strong>g, there are several ways to perform this<br />

particular task. Because <strong>C++</strong>Builder always creates a po<strong>in</strong>ter to the form object, I could have<br />

written the previous code like this:

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

Saved successfully!

Ooh no, something went wrong!