Go Up to Using the Main Form
To add a form to your project, select either File > New > VCL Form or File > New > Multi-Device Form, according to the type of application you are creating. You can see all your project's forms and their associated units listed in the Project Manager ( View > Project Manager ) and you can display a list of the forms alone by choosing View > Forms.
Adding a form to a project adds a reference to it in the project file, but not to any other units in the project. Before you can write code that references the new form, you need to add a reference to it in the referencing forms' unit files. This is called form linking.
A common reason to link forms is to provide access to the components in that form. For example, you can use form linking to enable a form that contains data-aware components in order to connect to the data-access components in a data module.
To link a form to another form
- Select the form that needs to refer to another.
- Choose File > Use Unit.
- Select the name of the form unit for the form to be referenced.
- Choose OK.
Avoiding circular unit references
When two forms must reference each other, it's possible to cause a "Circular reference" error when you compile your program. To avoid such an error, do one of the following:
- Place both uses clauses, with the unit identifiers, in the implementation parts of the respective unit files. (This is what the File > Use Unit command does.)
- Place one uses clause in an interface part and the other in an implementation part. (You rarely need to place another form's unit identifier in this unit's interface part.)
Do not place both uses clauses in the interface parts of their respective unit files. This generates the "Circular reference" error at compile time.