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.

VCL Components<br />

for buttons that are used as regular buttons on the form and that do not close the form. If you<br />

use any nonzero value for ModalResult, press<strong>in</strong>g the button will close the form and return the<br />

ModalResult value. For example, if you place a button on a form and set the ModalResult<br />

property to mrOk, press<strong>in</strong>g the button will close the form, and the return value from<br />

ShowModal() will be mrOk (1). Given that, then, you can do someth<strong>in</strong>g like the follow<strong>in</strong>g:<br />

<strong>in</strong>t result = MyForm->ShowModal();<br />

if (result == mrOK) DoSometh<strong>in</strong>g();<br />

if (result == mrCancel) return;<br />

Table 8.7 lists the ModalResult constants that VCL def<strong>in</strong>es.<br />

Table 8.7. VCL ModalResult constants.<br />

Constant Value<br />

NOTE<br />

mrNone 0<br />

mrOk 1<br />

mrCancel 2<br />

mrAbort 3<br />

mrRetry 4<br />

mrIgnore 5<br />

mrYes 6<br />

mrNo 7<br />

mrAll 8<br />

You don’t have to use one of the predef<strong>in</strong>ed ModalResult constants for<br />

your buttons. You can use any value you like. Let’s say, for example,<br />

you had a custom dialog box that could be closed by us<strong>in</strong>g a variety of<br />

buttons. You could assign a different ModalResult value to each button<br />

(100, 150, and 200, for example), and you would then know which<br />

button closed the dialog box. Any nonzero number is valid, up to the<br />

maximum value of an <strong>in</strong>t.<br />

You can get a program called ButtnTst from http://www.mcp.com/sams/codecenter.html; it<br />

demonstrates the use of ModalResult. The program allows you to execute a form conta<strong>in</strong><strong>in</strong>g<br />

several buttons. When you click a button, the ModalResult will be reported back on the ma<strong>in</strong><br />

form.<br />

297<br />

8

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

Saved successfully!

Ooh no, something went wrong!