Adding Forms

From RAD Studio
Jump to: navigation, search

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.

Linking 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

  1. Select the form that needs to refer to another.
  2. Choose File > Use Unit.
  3. Select the name of the form unit for the form to be referenced.
  4. Choose OK.
Linking a form to another form means that one form unit contains the header for the other form unit, meaning that the linked form and its components are now in scope for the linking form.
Linking a form to another form means that the uses clauses of one form unit contains a reference to the other form unit, meaning that the linked form and its components are now in scope for the linking form.

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.

See Also