RAD Studio |  |

Adding Forms
Linking forms | Avoiding circular unit references | See Also
Collapse All

To add a form to your project, select FileNewForm. You can see all your project's forms and their associated units listed in the Project Manager ( ViewProject Manager) and you can display a list of the forms alone by choosing ViewForms.

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'll often use form linking to enable a form that contains data-aware components 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 FileUse Unit.
3. Select the name of the form unit for the form to be referenced.
4. Choose OK.

Linking a form to another just means that the uses clauses of one form unit contains a reference to the other's 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 FileUse 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

TForm

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!