Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Анг-язык на 22.10.12.docx
Скачиваний:
1
Добавлен:
20.11.2019
Размер:
38.94 Кб
Скачать
  1. Using the main form

The first form you create and save in a project becomes, by default, the pro­ject's main form, which is the first form created at runtime. As you add forms to your projects, you might decide to designate a different form as your application's main form. Also, specifying a form as the main form is an easy way to test it at runtime, because unless you change the form creation order, the main form is the first form displayed in the running application.

  1. Hiding the main form

You can prevent the main form from appearing when your application starts by using the global Application variable.

To hide the main form at startup:

    1. Choose Project|View Source to display the main project file.

    2. Add the following code after the call to Application.CreateForm and before the call to Application.Run.

Application.ShowMainForm := False;

Forml .Visible := False; {the name of your main form may differ }

  1. Adding forms

To add a form to your project, select File|New|Form. You can see all your pro­ject'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.

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. (Thisjs 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.)

  1. Managing layout

At its simplest, you control the layout of your user interface by where you place controls in your forms. The placement choices you make are reflected in the control's Top, Left, Width, and Height properties. You can change these values at runtime to change the position and size of the controls in your forms.

Controls have a number of other properties, however, that allow them to auto­matically adjust to their contents or containers. This allows you to lay out your forms so that the pieces fit together into a unified whole.

  1. Using forms

When you create a form from the IDE, Delphi automatically creates the form in memory by including* code in the main entry point of your application function. Usually, this is the desired behavior and you don't have to do anything, to change it. That is, the main window persists through the duration of your program, so you would likely not change the default behavior when creating the form for your main window.

However, you may not want all your application's forms in memory for the du­ration of the program execution. That is, if you do not want all your application's dia­logs in memory at once, you can create the dialogs dynamically when you want them to appear.

Forms can be modal or modeless. Modal forms are forms with which the user must interact before switching to another form (for example, a dialog box requiring user input). Modeless forms are windows that are displayed until they are either obscured by another window or until they are closed or minimized by the user.