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.

<strong>C++</strong>Builder Extensions to <strong>C++</strong><br />

value is loaded aga<strong>in</strong> from the form file when the form is loaded <strong>in</strong> the Form Designer, or<br />

when the form is displayed <strong>in</strong> the application. By default all properties <strong>in</strong> the __published<br />

section of the class declaration will be stored automatically. Properties that are conta<strong>in</strong>ed <strong>in</strong><br />

the public section of a component’s class declaration are not automatically stored. To<br />

specifically store a property, you set the stored property to true:<br />

__property <strong>in</strong>t Value { read=FValue, write=SetValue, stored=true };<br />

As I said, all properties <strong>in</strong> the __published section of the class declaration will be stored<br />

automatically. This is almost always what you want, so you may never have to use the stored<br />

specifier for your published properties. But if, for some reason, you want to specifically<br />

preclude a property from be<strong>in</strong>g stored, you can specify a value of false for the stored<br />

specifier:<br />

__property <strong>in</strong>t Value { read=FValue, write=SetValue, stored=false };<br />

Most of the time you can allow <strong>C++</strong>Builder to use the default storage action for your<br />

properties.<br />

Extend<strong>in</strong>g Base Class Properties<br />

It is common to extend a property that is provided <strong>in</strong> the base class of the component you<br />

have created. One of the most common reasons to do so is to change the default value of the<br />

property. For <strong>in</strong>stance, let’s say you had derived a new component from the TLabel<br />

component and that this new component needed to have its text centered. In that case you<br />

could redeclare the Alignment property as follows:<br />

__property Alignment = { default=taCenter };<br />

When your new component is placed on a form <strong>in</strong> the Form Designer, the Alignment<br />

property will now default to taCenter. Note that you only need to add whatever specifiers<br />

are needed to change the property. In this example the default specifier is the only one that<br />

is changed, so it is the only one listed.<br />

Another common need is to override the default behavior of a component when a particular<br />

property is written to. In that case you could redeclare the property and just change the write<br />

specifier:<br />

__property Alignment = { write=MyWriteAlignment };<br />

When you redeclare a published property, be sure that you place the redeclaration <strong>in</strong> the<br />

__published section of the class declaration.<br />

495<br />

<strong>14</strong>

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

Saved successfully!

Ooh no, something went wrong!