constructor Create(AOwner: TComponent); virtual;
__fastcall virtual TComponent(TComponent* AOwner);
Allocates memory and constructs a safely initialized instance of a component.
- Establishes the relationship of a component and its Owner, as indicated by the
- Sets the ComponentStyle property to
csInheritable, meaning that the component can be inherited by a descendent form type.
It is not necessary to explicitly create components added in the Form Designer. These components are created automatically when the application is run, and they are destroyed when the application is closed.
For components created programmatically, that is, not created in the Form Designer, call Create and pass in an owner component as the
AOwner parameter. The owner disposes of the component when it is destroyed. If the component is not owned, then use Free when it needs to be destroyed.
Tip: When passing in
Selfas the Owner parameter, consider what
Selfreferences. If a component creates another component in one of its methods, then
Selfrefers to the first component and not the component being created, which is then owned by the first component.
Note: The TComponent constructor is virtual in part to allow polymorphic instantiation of class references. This is critical to the streaming system and to the Form Designer. Do not forget to use the override directive when declaring a new component's Create constructor.