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:
- Choose either:
- File
New
Unit.
- File
New
Other to display the New Items dialog box, select Delphi Projects
Delphi Files
Unit, and choose OK. The IDE creates a new unit file and opens it in the Code editor.
- Save the file with a meaningful name.
- Derive the component class.
To open an existing unit:
- 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.
- Derive the component class.