RAD Studio |  |

TComponent Branch
See Also
Collapse All

The TComponent branch contains classes that descend from TComponent but not TControl. Objects in this branch are components that you can manipulate on forms at design time but which do not appear to the user at runtime. They are persistent objects that can do the following:

- Appear on the Tool palette and be changed on the form.
- Own and manage other components.
- Load and save themselves.

Several methods introduced by TComponent dictate how components act during design time and what information gets saved with the component. Streaming (the saving and loading of form files, which store information about the property values of objects on a form) is introduced in this branch. Properties are persistent if they are published and published properties are automatically streamed.

The TComponent branch also introduces the concept of ownership that is propagated throughout the component library. Two properties support ownership: Owner and Components. Every component has an Owner property that references another component as its owner. A component may own other components. In this case, all owned components are referenced in the component's Components property.

The constructor for every component takes a parameter that specifies the new component's owner. If the passed-in owner exists, the new component is added to that owner's Components list. Aside from using the Components list to reference owned components, this property also provides for the automatic destruction of owned components. As long as the component has an owner, it will be destroyed when the owner is destroyed. For example, since TForm is a descendant of TComponent, all components owned by a form are destroyed and their memory freed when the form is destroyed. (Assuming, of course, that the components have properly designed destructors that clean them up correctly.)

If a property type is a TComponent or a descendant, the streaming system creates an instance of that type when reading it in. If a property type is TPersistent but not TComponent, the streaming system uses the existing instance available through the property and reads values for that instance's properties.

Some of the classes in the TComponent branch include:

- TActionList, a class that maintains a list of actions, which provides an abstraction of the responses your program can make to user input.
- TMainMenu, a class that provides a menu bar and its accompanying drop-down menus for a form.
- TOpenDialog, TSaveDialog, TFontDialog, TFindDialog, TColorDialog, and so on, classes that display and gather information from commonly used dialog boxes.
- TScreen, a class that keeps track of the forms and data modules that an application creates, the active form, the active control within that form, the size and resolution of the screen, and the cursors and fonts available for the application to use.

Components that do not need a visual interface can be derived directly from TComponent. To make a tool such as a TTimer device, you can derive from TComponent. This type of component resides on the Tool palette but performs internal functions that are accessed through code rather than appearing in the user interface at runtime.

See Working with components for details on setting properties, calling methods, and working with events for components.

See Also

TPersistent Branch

Objects

TControl Branch

TObject Branch

TWinControl/TWidgetControl Branch

TComponent

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