RAD Studio VCL Reference
TComponent.Create Constructor

Allocates memory and constructs a safely initialized instance of a component.

constructor Create(AOwner: TComponent); virtual;
virtual __fastcall TComponent(TComponent * AOwner);

All objects have a Create method that constructs the object. TComponent redefines Create so that, for components, Create also: 

establishes the relationship of a component and its Owner, as indicated by the AOwner parameter 

sets the ComponentStyle property to csInheritable, meaning that the component can be inherited by a descendant 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 Self as the Owner parameter, consider what Self references. If a component creates another component in one of its methods, then Self refers 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.


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!