Chapter One Introduction to-delphi (v.) (3)

Source: Internet
Author: User

1.5.1.1 Create a routine that contains the About box

As an example, we first create an application with a main form and a simple about box:

Create a new project in Delphi and add a button widget to the empty window. We use it as the main form to bring up the About window when the button part is pressed. Below we directly to the creation of the window.

Select the main menu of the file New item, in the new page, select the form template, Delphi will automatically create an empty form Form2. You can design the About box on it, such as adding a label to display various information, adding a picture help note, and so on. Setting the Form2 BorderStyle property to Bsdialog, the window becomes a dialog box that cannot be resized at run time.

The following programming implementation of the main form to the About box display control. It is likely that at design time, two forms overlap and Form1 is obscured. Using SHIFT+F12 to generate the View Form dialog box, you can select the name of the window, bring up the desired form FORM1, double-click the button part on it, and add the following procedure to the event-handling process:

Procedure Tform1.button1click (Sender:tobject);

Begin

Form2.show;

End

Because the Form1 form calls the about form, you must describe the reference in Form1 's library unit program. Add the library unit name Unit2 to the uses after Unit1. To run the program, press the button on the main form to appear in the About box. Click outside the box to return to the main form.

Add a button to the About form, set the button's Modalresult property to Mrok, and change the button's caption to OK. Such a pattern of the About box has been built. Change the code for the onclick process of Button1 in form Form1 as follows:

Form2.showmodal;

And then run the program, in addition to the same functionality as the above display About dialog box, the program only when the user presses the About box button or by the About window control icon closes the window, will not return to the main form, but not with the first form interaction behavior. This is the main difference between the method show and the ShowModal.

1.5.1.2 specifies that the form is automatically created

Above we simply generated a two-form application with the About box, and the second form will be created automatically when the application starts at runtime. Forms remain hidden, but still occupy windows resources. In large applications, it is sometimes not desirable to automatically create all forms when the application loads. Delphi can specify which forms are automatically created.

Use Project Options,delphi to display the Project Options dialog box. If forms is not the current page, move the label to make it visible. As shown in Figure 1.12:

The TextEdit routine (... \delphi 2.0\demos\doc\textedit.dpr) for Delphi loading is shown. Enter the name of the main form in the MainForm body box. When the application starts, the main form automatically opens and gets the input focus. For MDI applications, the Formstyle property of the main form must be set to Fsmdiform. A form that is automatically created at startup is listed in the Auto-created Forms list box, and all forms of the project file are in this column by default.

If you do not need to create a form automatically, use the arrow buttons to move the form to the Available Forms list box. Automatically created forms can be displayed with the Show method, and when not created automatically, you must programmatically implement the display of the form. In TextEdit Engineering, define a variable editform for a teditform type, using the following code to display the second form:

Begin

EditForm: = Teditform.create (Self);

Editform.open (Openfiledialog.filename);

Editform.visible: = True;

End;

That is, you must use the Create method to create the form, and set the form's Visible property to True.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.