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.

308 Day 8<br />

■ Font<br />

■ Color<br />

■ Pr<strong>in</strong>t<br />

■ Pr<strong>in</strong>ter Setup<br />

■ F<strong>in</strong>d<br />

■ Replace<br />

The common dialog boxes are found on the Dialogs tab of the Component Palette. These<br />

components are nonvisual because they do not have a visual design-time <strong>in</strong>terface. The<br />

follow<strong>in</strong>g sections discuss each of these dialog boxes with one exception—I’ll leave the<br />

discussion of the Pr<strong>in</strong>t and Pr<strong>in</strong>ter Setup dialog boxes for later, when I discuss pr<strong>in</strong>t<strong>in</strong>g.<br />

The Execute Method<br />

NOTE<br />

One th<strong>in</strong>g that all the common dialog boxes have <strong>in</strong> common is the Execute() method, which<br />

is used to create and display the dialog box. The dialog box is displayed modally except for<br />

the F<strong>in</strong>d and Replace dialog boxes, which are displayed modelessly. Execute() returns true<br />

if the user clicked the OK button, double-clicked a file name, or pressed Enter on the<br />

keyboard. Execute() returns false if the user clicked the Cancel button, pressed the Esc key,<br />

or closed the dialog box with the system close box. A common dialog box is often<br />

implemented like this:<br />

if (OpenDialog->Execute()) {<br />

// user pressed OK so use the filename<br />

Memo->L<strong>in</strong>es->LoadFromFile(OpenDialog->FileName);<br />

}<br />

return;<br />

This code displays the File Open dialog box and gets a filename from the user. If the user<br />

clicked the OK button, the code <strong>in</strong>side the if block is executed and the file is loaded <strong>in</strong> to<br />

a Memo component. If OK was not pressed, the code <strong>in</strong>side the if block is ignored and no<br />

action takes place.<br />

The code used <strong>in</strong> the previous snippet is another example of <strong>C++</strong><br />

shortcut syntax. The first l<strong>in</strong>e:<br />

if (OpenDialog->Execute()) {<br />

is equivalent to this:<br />

if (OpenDialog->Execute() == true) {<br />

Use either method, but the first is preferred.

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

Saved successfully!

Ooh no, something went wrong!