Documente Academic
Documente Profesional
Documente Cultură
ITEC319
Rapid Application
Development
Forms in Delphi
In Delphi, whenever a form is created in the project, two files
are created on the disk.
A .dfm file that creates a form file by deriving a class from
TForm.
A .pas file that creates a unit for the class definition.
1
Forms in Delphi
Multiple components of the same type can also be placed
onto the form without selecting the component from the
Component palette every time.
It can be done by pressing to the shift key on the keyboard
while selecting the component from the component palette.
After placing the components, mouse pointer (arrow) in the
tool palette window can be clicked to deselect the component.
2
Working with Multiple Forms in Delphi
5. Choose File->New Form from the main menu (or click the
New Form button on the toolbar) to create a new form.
6. Resize the new form so that it is about 50 percent of the size
of the main form.
7. Change the new form's name to secondform and caption to
Second Form.
8. Choose File->Save from the main menu and use second as a
unit file name.
9. Select the firstform and get into the onclick event of
showform2 button.
10. Type the following code:
procedure TMainForm.ShowFrom2Click(Sender: TObject);
begin
secondform.showmodal; // displays the second form on the screen
end;
5
3
Working with Multiple Forms in Delphi
In this example, when showmodal method is called for
secondform, it will be displayed on the screen and firstform
will not be accessible anymore until secondform is closed.
In Delphi, a modal form is one that must be dismissed before
the user can continue using the other forms in the application.
For example, most of the dialog boxes are modal.
To execute a modal form, showmodal method is called.
Dialog boxes can also have a Help button and usually they are
not usually re-sizeable.
4
Multiple Document Interface (MDI)
On the other hand, each MDI child windows must have the
FormStyle property set to fsMDIChild.
10
5
Form Properties (Design and Runtime)
The ActiveControl property is used to set the control that will have
focus when the form is activated.
11
You can specify the client area width and height rather than the full
form's width and height by using the ClientWidth and ClientHeight
properties. The client area of the form is the area inside of the
borders and below the title bar and menu bar. Setting these
properties makes automatic changes to the Width and Height
properties.
12
6
Form Properties (Design and Runtime)
The Font property specifies the font that the form uses. The
important issue to understand here is that the form's font is
inherited by any components placed on the form. This also means
that you can change the font used by all components at one time by
changing just the form's font.
The Icon property sets the icon that is used on the title bar of a
form. If the BorderStyle property of a form is set to bsNone, then
the Icon property is ignored.
13
The Position property determines the size and position of the form
when the form is initially displayed on the screen.
poDesigned causes the form to be displayed in the exact
position that it was designed.
poDefault enables Windows to set the size and position of the
form.
poScreenCenter causes the form to be displayed in the center
of the screen.
14
7
Form Properties (Design and Runtime)
15
The ClientRect property contains the top, left, right, and bottom
coordinates of the client area of the form.
For example, you might need to know the client area's width
and height in order to place a bitmap on the center of the form.
16
8
Form Properties (Runtime Only)
17