The following describes how to compile, link, and create an application with the simplest multiple forms.
1,Select 【File | new | Application] To create a new project;
2,Create by defaultForm1WindowNameChange the attribute to"Mainform",CaptionChange the attribute to"Multiple forms Test Program";
3,Save the project. AndMain. PasName save unit,Multiple. DPRSave the project by name;
4,InMainformPut a button on the form, and makeNameForBtnshowform2",CaptionThe property is"Showform2", As follows:
5,Select 【File | new | form] (Or click"New FormCreate a new window. The default name of the newly created window isForm1, Drag the lower-right corner of the window to zoom in and out the window, so that the window is smaller than mainform and displayed in the center of mainform, as shown below:
6,SetNameChange the attribute to"Secondform",CaptionChange the attribute to"A second form";
7,Select"Save File"Button to save this unitSecond. Pas;
8,SelectLabelComponents, and drag and dropSecondformAnd put itsCaptionChange the attribute to"This is the second form", And set the size in the font attribute to your favorite size, and place the label in the central position of secondform;
9,ClickMainformWindow, and double-click"Showform2"Button, the code editor will be displayed, and the cursor is positioned to enter the code method (double-click the button to generateOnclickEvent), as follows:
10,Enter the following code:
Procedure tmainform. btnshowform2click (Sender: tobject); begin secondform. showmodal; {display secondform mode window} end;
11,RunF9This program will get a message box as follows:
ClickYesButton, Delphi will add the second unit to the Main UnitUses list.
Click againF9After running the program, click"Showform"Button. The second window is displayed. ClickClose (X)You can close the second window.
Add Unit
The11In step, the unit is added to the uses list by using the Delphi reminder. You can also add the Unit by yourself, either by typing in the uses list in Main. PasSecondUnit. You can also select 【File | use Unit].
Now we return Step 1 (you can find"Use second;).
SelectedMainformWindow, and then click 【File | use Unit]. The use unit dialog box is displayed as follows:
Select the unit to add and clickOK, Delphi will add this unit to the current formUses list.
If you install"Cnpack ide wizards"Expert package, through the main menu 【File | use Unit] The following dialog box will pop up. In fact, the function is the same as the use unit dialog box that comes with Delphi, as shown below:
Note
The Unit displayed in the use unit dialog box is only the unit name that already exists in the project and is not included in the current unit. Included cells are no longer displayed in the list box.
The above code passes the test in Delphi. Download the sample code:Multi-Window application .rar