MDI and SDI forms

Any form you design can be implemented in your application as a Multiple Document Interface (MDI) or Single Document Interface (SDI) form. In an MDI application, more than one document or child window can be opened within a single parent window. This is common in applications such as spreadsheets or word processors. An SDI application, by contrast, normally contains a single document view.

It's probably more common to design an MDI form as such from the beginning, but you can change forms you create into MDI or SDI forms simply by changing their FormStyle property.

The following table displays the possible FormStyle property settings and their purpose. Table 3.5 FormStyle property settings

FormStyle value Creates Comments fsNormal A standalone (SDI) form fsMDIForm An MDI parent or frame form fsMDIChild An MDI child form fsStayOnTop A standalone form that stays on top of other open forms at run time

► To demonstrate how MDI parent forms contain child forms, try the following.

1 Start a new, blank project and add a new, blank form.

2 Set the FormStyle property for Forml to fsMDIForm, and for Forml to fsMDIChild.

3 Add a Panel component to Forml, and change its Alignment property to AlTop.

4 Add a SpeedButton component to the panel, and generate the following OnClick event handler for it:

procedure TForm1.SpeedButton1Click(Sender: TObject); begin

Form2.Show; end;

5 Add Unitl to Unitl's uses clause.

6 Run the program, and click SpeedButtonl. Forml opens inside Forml. Figure 3.10 Sample MDI child and parent forms

15

Formi

I- -

Panell

ID

Form2

■ -I-

You can resize and move either form, but the child form always stays within the borders of the parent.

Here are some rules about MDI parent and child forms:

• The MDI parent form must always be the application's main form.

If the MDI parent form isn't specified as the application's main form, the application won't be correctly compiled.

This form can contain other forms at run time.

This form is contained by the MDI parent at run time.

  • There can be only one form of stylefsMDIForm per application.
  • The application's main form can never be of type MDIChild. This would also prevent the application from being properly compiled.
  • In general, you should remove the MDI child form from the Auto-create forms list on the Forms page of the Project Options dialog box.

This is because for true MDI applications, you create multiple instances of a single child form at run time. If, on the other hand, your application uses only one instance of each of several different types of child forms, as might be the case in a database application, you probably don't need to create each child form at run time. In this case, you needn't remove the forms from the Auto-create list.

For more information about the Auto-create forms list, see "Specifying forms to autocreate" on page 113, or search online Help for "instantiating forms." For more information about MDI applications, see Chapter 10, which documents how to write the demo application, TEXTEDIT.DPR.

The next section describes the Delphi Menu Designer, which you use to add menus to your forms. For information about adding tool bars and status lines to your forms, see Chapter 12.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Responses

  • HAZEL
    How many parent forms can be in an mdi application?
    9 years ago
  • REGINARD BOFFIN
    What is mdi and sdi application in delphi?
    9 years ago

Post a comment