Components often have long lists of properties with usable default values:
class PACKAGE TMySpecialComboBox : public TCustomComboBox
{
public:
__fastcall TMySpecialComboBox(TComponent *Owner);
// ...
private:
// ...
bool fetch_all_;
bool rename_;
TColor background1_, background2_, background3_;
// ...
__published:
// ...
__property bool FetchAll = {read = fetch_all_, write = fetch_all_,
default = false};
__property bool Rename = {read = rename_, write = rename_,
default = false};
__property TColor Background1 = {read = background1_, write = background1_,
default = clWindow};
__property TColor Background2 = {read = background2_, write = background2_,
default = clWindow};
__property TColor Background3 = {read = background3_, write = background3_,
default = clWindow};
// ...
};
Storing all this information in the form file wastes space and reading it back takes time, which is not desirable, considering that in most cases, few of the defaults change.
To minimize the volume of data in the form file, you can specify a default value for each property (when writing to the form file, the form editor skips any properties whose values haven't been changed).
Note that doing so doesn't set the default value:
Note: Property values are not automatically initialized to the default value. That is, the default directive controls only when property values are saved to the form file, but not the initial value of the property on a newly created instance.
the constructor is responsible for doing that:
__fastcall TMySpecialComboBox::TMySpecialComboBox(TComponent* Owner)
: TCustomComboBox(Owner), // ...
{
FetchAll = false; // how to get the default value ?
Rename = false; // how to get the default value ?
Background1 = clWindow // how to get the default value ?
// ...
}
but writing initialization in this way is very error prone.
How can I get the default value of a __property
?