Show: Delphi C++
Display Preferences

TComponent Branch

From RAD Studio
Jump to: navigation, search

Go Up to Objects, Components, and Controls


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 run time. 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, which 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 Components property of the component.

The constructor for every component takes a parameter that specifies the owner of the new component. If the passed-in owner exists, the new component is added to Components list of that owner. 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 the properties of that instance.


Some of the classes in the TComponent branch include:

  • TActionList, a class that maintains a list of actions used with components and controls, such as menu items and buttons.
  • 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 provide commonly used dialog boxes.
  • TScreen, a class that keeps track of what forms and data modules have been instantiated by the application, the active form, and 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 run time.

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

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance