Show: Delphi C++
Display Preferences

Specifying the New Default Property Value

From RAD Studio
Jump to: navigation, search

Go Up to Modifying the Component Object


When Delphi stores a description of a form in a form file, it stores the values only of properties that differ from their defaults. Storing only the differing values keeps the form files small and makes loading the form faster. If you create a property or change the default value, it is a good idea to update the property declaration to include the new default. Form files, loading, and default values are explained in more detail in Making Components Available at Design Time.

To change the default value of a property, redeclare the property name, followed by the directive default and the new default value. You don't need to redeclare the entire property, just the name and the default value.

For the word-wrapping memo component, you redeclare the WordWrap property in the published part of the object declaration, with a default value of False:

type
  TWrapMemo = class(TMemo)
  .
  .
  .
  published
    property WordWrap default False;
  end;


//header file
class PACKAGE TYellowMemo : public TMemo
{
public:
    virtual __fastcall TYellowMemo(TComponent* Owner);
__published:
    __property Color = {default=clYellow};
};


//implmentation file
__fastcall TYellowMemo::TYellowMemo(TComponent* AOwner) : TMemo(AOwner)
{
  Color = clYellow;
  WordWrap = false;
}


//header file with WordWrap as default value of false:
class PACKAGE TYellowMemo : public TMemo
{
public:
    virtual __fastcall TYellowMemo(TComponent* Owner);
__published:
    __property Color = {default=clYellow};
    __property WordWrap = {default=false};
};

Specifying the default property value does not affect the workings of the component. You must still initialize the value in the component's constructor. Redeclaring the default ensures that Delphi knows when to write WordWrap to the form file.

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance