Form files

 

Forms are a very visible part of most Delphi projects. Normally, you design forms using Delphi's visual tools, and Delphi stores a description of the designed forms in form files. Form files (extension .dfm or .xfm) describe each component in your form, including the values of all persistent properties. You do not specify the form file programmatically; you simply create the form by selecting components from the Component palette and customizing them to suit your needs by setting properties and events with the Object Inspector.

Each form in a Delphii project also has an associated unit. The unit contains the source code for any event handlers attached to the events of the form or the components it contains. A unit associated with a form is sometimes called a form unit. When you save a form unit or a project containing unsaved forms, Delphi prompts you to enter a name for each unit, which it uses as the name of the unit file, appending the extension .pas. The form file gets the same name, but with the extension .dfm for Windows projects and xfm for CLX projects. You can use any extension you want on your unit files, but Delphi expects the .dfm or xfm extension on the corresponding form file.

Warning:   You can’t define more than one form in a single unit. This is because each dfm or xfm file can only describe a single form (or data module).

Form files can be saved in either binary or text format. The Environment Options dialog lets you indicate which format you want to use for newly created forms.

To view the text version of .dfm or xfm files in the Code editor:

1.       Select the form.

2.       Right-click and choose View As Text.

To return to viewing the form graphically, follow the above steps and choose View As Form.

To change the format (text or binary) in which the form file is saved:

1.       Select the form.

2.       Right-click and check or uncheck Text DFM (VCL applications) and Text XFM (CLX applications).

Tip:    You may want to archive your forms as text as they are less susceptible to data corruption.