Overriding the constructor
When a component is placed on a form at design time, or when an application constructs a component at runtime, the component’s constructor sets the property values. When a component is loaded from a form file, the application sets any properties changed at design time.
Note: When you override a constructor, the new constructor must call the inherited constructor before doing anything else. For more information, see Overriding methods.
For this example, your new component needs to override the constructor inherited from TMemo to set the WordWrap property to False. To achieve this, add the constructor override to the forward declaration, then write the new constructor in the implementation part of the unit:
type
TWrapMemo = class(TMemo)
public { constructors are always public }
constructor Create(AOwner: TComponent)
override
{ this syntax is always the same }
end;
...
constructor TWrapMemo.Create(AOwner: TComponent)
{ this goes after implementation }
begin
inherited Create(AOwner)
{ ALWAYS do this first! }
WordWrap := False
{ set the new desired value }
end;
Now you can install the new component on the Component palette and add it to a form. Note that the WordWrap property is now initialized to False.
If you change an initial property value, you should also designate that value as the default. If you fail to match the value set by the constructor to the specified default value, Delphi cannot store and restore the proper value.