Creating a Unit File

From RAD Studio
Jump to: navigation, search

Go Up to Creating a Component with the Component Wizard

A unit is a separately compiled module of Delphi code. Delphi uses units for several purposes. Every form has its own unit, and most components (or groups of related components) have their own units as well.

When you create a component, you either create a new unit for the component or add the new component to an existing unit.

To create a new unit for a component:

  1. Do either of the following choices:
    • File > New > Delphi or C++Builder Unit .
    • File > New > Other to display the New Items dialog box, select Delphi or C++Builder Projects > Delphi or C++Builder Files > Unit , and choose OK. The IDE creates a new unit file and opens it in the Code Editor.
  2. Save the file with a meaningful name.
  3. Derive the component class.

To open an existing unit:

  1. Choose File > Open and select the source code unit to which you want to add your component.

    Note: When adding a component to an existing unit, make sure that the unit contains only component code. For example, adding component code to a unit that contains a form causes errors in the Tool Palette.

  2. Derive the component class.

See Also