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.

The <strong>C++</strong>Builder IDE Explored: Projects and Forms<br />

7. Change the new form’s Name property to SecondForm and the form’s Caption<br />

property to A Second Form.<br />

8. Choose File | Save from the ma<strong>in</strong> menu (or click the Save File button on the<br />

toolbar) and save the file with the name Second.<br />

9. Choose a Label component and drop it on the new form. Change the label’s<br />

Caption property to This is the second form. Change the label’s size and color as<br />

desired. Center the label on the form. Your form should now look roughly similar<br />

to the one <strong>in</strong> Figure 6.7.<br />

Figure 6.7.<br />

The form up to this<br />

po<strong>in</strong>t.<br />

10. Click on the ma<strong>in</strong> form. Notice that the second form is covered by the ma<strong>in</strong> form.<br />

Double-click the Show Form 2 button. The Code Editor is displayed, and the<br />

cursor is placed just where you need it to beg<strong>in</strong> typ<strong>in</strong>g code.<br />

11. Type <strong>in</strong> code so that the function looks like this (you have to type only one l<strong>in</strong>e of<br />

code):<br />

void __fastcall TMa<strong>in</strong>Form::ShowForm2Click(TObject *Sender)<br />

{<br />

SecondForm->ShowModal();<br />

}<br />

12. Run the program.<br />

At this po<strong>in</strong>t you will get a compiler error that says Undef<strong>in</strong>ed symbol ‘SecondForm’.<br />

Hmmm…SecondForm should be a valid symbol because that’s the name of the second form<br />

we created…I wonder…Aha! Remember that we have two source files with a header for each<br />

source file. The problem is that the Ma<strong>in</strong>Form unit can’t see the declaration for the SecondForm<br />

variable (which is a po<strong>in</strong>ter to the TSecondForm class). We have to tell it where to f<strong>in</strong>d the class<br />

declaration. (Recall Day 2, “Wad<strong>in</strong>g In Deeper.” We have to #<strong>in</strong>clude the header for<br />

181<br />

6

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

Saved successfully!

Ooh no, something went wrong!