Tcomponent class
The tcomponent class is directly derived from tpersistent. The unique feature of tcomponent is that its attributes can be controlled by objectinspector during design and can have other components. Non-visual components are also derived from tcomponent, so they also inherit the capabilities that can be controlled during design. A typical example of a non-visual object derived from tcomponent is the ttimer component. The ttimer component is an invisible component, but it can still be obtained on the component panel. Tcomponent defines several important attributes and methods, which will be described in subsequent sections.
1. Properties of tcomponent:
Owner: component owner
Componentcount: number of components owned by a component
Componentindex: position of a component in its owner list. The value of the first component in the list is 0.
Components: an attribute array that contains a list of components owned by a component. The value of the first component in the list is 0.
Componentstate: This attribute contains the current status of the tcomponentstate component. (More detailed explanation:
Componentstate attributes
Corresponding object: all components.
Declaration: Property componentstate: tcomponentstate;
Function: The componentstate attribute is used to describe the component status. The componentstate attribute is valid at runtime and read-only. It is of the tcomponentstate type and is declared as: tcomponentstate = set of (csloading, csreading, cswriting, csdestroying, csdesigning, csancestor, csupdating, csfixups); tcomponentstate is a collection, you can combine them to export the component status. Some common labels include the following:
Csdesigning: the Delphi environment is the design method, so you can edit components.
Csreading: The component reads its attribute values from a stream.
Cswriting: The component writes its attribute value to a stream.
The compnentstate attribute is used internally by components to ensure that some programs can be executed. Therefore, you do not need to access componentstate frequently .)
Componentstyle: component style. It can be set to csinheritable or cscheckpropavail. For more information, see online help.
Name: component name
Tag: an integer with no definite meaning. Component writers cannot use it, but application writers can use it. Because the value is an integer type, data structure pointers (even object instances) can be distinguished through it.
Designinfo: Do not use this attribute. It is used by the Form Designer.
2. tcomponent Method
Tcomponent defines several methods and can have other components that can be controlled on the Form Designer. Tcomponent defines the component constructor create (). The constructor is responsible for creating component instances and passing the specified component owner through parameters. Unlike tobject. Create (), tcomponent. Create () is virtual. To implement the constructor, The tcomponent derived class must overwrite this method. Although you can declare other constructors in the component class, VCL can only use the tcomponent. Create () constructor when creating component-based instances based on streams during the design and runtime.
Tcomponent. Destroy (): The Destructor is used to release components and all their resources.
Tcomponent. Destroying (): The method is used to set a state for the component and its components, indicating that they are being deleted.
Tcomponent. destroycomponents (): This method is used to analyze components. Generally, you do not need to use these methods directly.
Tcomponent. findcomponents (): This method allows you to find components with only names. Suppose you know that there is a tedit component named edit1 in the main form. When you want to find this component, you can obtain its instance pointer by executing the following code:
Editinstance: = findcomponent ('edit'); in this example, editinstance is of the tedit type. If not found, findcomponent () returns nil.
Tcomponent. getparentcomponent (): The method returns the instance of the parent component. If the component does not have a parent, this method returns nil.
Tcomponent. hasparent (): returns a Boolean value indicating whether the component has a parent. Note that this method has nothing to do with the component owner.
Tcomponent. insertcomponent (): adds a component to the method, which is owned by the component that calls the method;
Tcomponent. removecomponent (): removes a component from the component that calls this method. Generally, you do not need to call these methods because the CREATE () constructor and destroy () destructor of the component automatically call them.
Tcomponent class
The tcomponent class is directly derived from tpersistent. The unique feature of tcomponent is that its attributes can be controlled by objectinspector during design and can have other components. Non-visual components are also derived from tcomponent, so they also inherit the capabilities that can be controlled during design. A typical example of a non-visual object derived from tcomponent is the ttimer component. The ttimer component is an invisible component, but it can still be obtained on the component panel. Tcomponent defines several important attributes and methods, which will be described in subsequent sections.
1. Properties of tcomponent:
Owner: component owner
Componentcount: number of components owned by a component
Componentindex: position of a component in its owner list. The value of the first component in the list is 0.
Components: an attribute array that contains a list of components owned by a component. The value of the first component in the list is 0.
Componentstate: This attribute contains the current status of the tcomponentstate component. (More detailed explanation:
Componentstate attributes
Corresponding object: all components.
Declaration: Property componentstate: tcomponentstate;
Function: The componentstate attribute is used to describe the component status. The componentstate attribute is valid at runtime and read-only. It is of the tcomponentstate type and is declared as: tcomponentstate = set of (csloading, csreading, cswriting, csdestroying, csdesigning, csancestor, csupdating, csfixups); tcomponentstate is a collection, you can combine them to export the component status. Some common labels include the following:
Csdesigning: the Delphi environment is the design method, so you can edit components.
Csreading: The component reads its attribute values from a stream.
Cswriting: The component writes its attribute value to a stream.
The compnentstate attribute is used internally by components to ensure that some programs can be executed. Therefore, you do not need to access componentstate frequently .)
Componentstyle: component style. It can be set to csinheritable or cscheckpropavail. For more information, see online help.
Name: component name
Tag: an integer with no definite meaning. Component writers cannot use it, but application writers can use it. Because the value is an integer type, data structure pointers (even object instances) can be distinguished through it.
Designinfo: Do not use this attribute. It is used by the Form Designer.
2. tcomponent Method
Tcomponent defines several methods and can have other components that can be controlled on the Form Designer. Tcomponent defines the component constructor create (). The constructor is responsible for creating component instances and passing the specified component owner through parameters. Unlike tobject. Create (), tcomponent. Create () is virtual. To implement the constructor, The tcomponent derived class must overwrite this method. Although you can declare other constructors in the component class, VCL can only use the tcomponent. Create () constructor when creating component-based instances based on streams during the design and runtime.
Tcomponent. Destroy (): The Destructor is used to release components and all their resources.
Tcomponent. Destroying (): The method is used to set a state for the component and its components, indicating that they are being deleted.
Tcomponent. destroycomponents (): This method is used to analyze components. Generally, you do not need to use these methods directly.
Tcomponent. findcomponents (): This method allows you to find components with only names. Suppose you know that there is a tedit component named edit1 in the main form. When you want to find this component, you can obtain its instance pointer by executing the following code:
Editinstance: = findcomponent ('edit'); in this example, editinstance is of the tedit type. If not found, findcomponent () returns nil.
Tcomponent. getparentcomponent (): The method returns the instance of the parent component. If the component does not have a parent, this method returns nil.
Tcomponent. hasparent (): returns a Boolean value indicating whether the component has a parent. Note that this method has nothing to do with the component owner.
Tcomponent. insertcomponent (): adds a component to the method, which is owned by the component that calls the method;
Tcomponent. removecomponent (): removes a component from the component that calls this method. Generally, you do not need to call these methods because the CREATE () constructor and destroy () destructor of the component automatically call them.