Fourth chapter-Text editor design (i) (1)

Source: Internet
Author: User
Tags save file

This chapter describes the use of multiple text interface (MDI), multiple page interface (MPI) technology, Tmemo,tedit controls in the VCL Library, and common dialog boxes for text editing. The MPIEDIT.DPR we developed is a text-editing utility that enables the following functions:

The editing environment for MDI

The editing environment of MPI

Create open, edit, save file

Find and replace the string specified in the file

Copy, paste, and cut strings

Set File font size

Print files

This chapter describes how to implement the above features in Delphi through the Mpiedit utility.

A text editor is a commonly used application. Users edit a variety of files in the editor, Exchange data between multiple files, make various property settings for the file, and print the file as they want.

4.1 Multi-Text interface

A multi-text interface is a form of interface in which two or more files are opened simultaneously in one application. For example, when a word processor can open multiple files at the same time, users can easily switch between multiple files.

MDI applications provide a convenient way for users to observe and exchange data across multiple documents in the same work area. MDI work areas can be divided into parent forms and subforms, and in Dephi MDI applications, the parent form is usually the main form of the program.

In the MDI, a form outside of the parent form is called a subform, and the document or other data opens in the subform. These documents can be of the same file format, or can be in different file formats with the support of the application.

In the design phase, you can create an MDI parent form as the main application form, or create a subform template. Delphi allows multiple subform types to be created, but the MDI application supports only one of them.

This section describes the basic steps for creating an MDI application:

Create main window

Creating child windows

Create the main Window menu

Fusion Menu

Create child windows at run time

4.1.1 Create a parent window

In an MDI application, the main window provides a working area for the application document. This area opens one or more child windows, and creating a parent window is the first step to building an MDI application.

Creating a parent window is similar to other windows, except that the Formstyle property of the form is set.

The Formstyle property determines whether a form is a parent window or a child window, or is not an MDI type. Formstyle can only be determined at the design stage. Set the Formstyle property to Fsmdiform in the Object Inspector window. It is worth noting that the parent window should be defined as the main form of the application, otherwise the program compiles with errors.

4.1.2 Create child windows

The design phase creates a template for the child window, and the user is running into an instance that uses the template. The child window is visible by default, and if the application is running into the Create child window, do not let Delphi automatically create it.

The form's Formstyle property is set to Fsmdichild when the child window is created. If the program creates child windows at run time, the

1. Choose options| Project menu, the system pops up the Auto Create List dialog box;

2. Select the Neutron window in the automatic creation list;

3. Click the > button to move the child window to the list of available (Available) forms;

4. and click the OK button to exit.

4.1.3 Create Application menu and menu Fusion

The parent window's menu should act as the main application menu. If a child window has a menu, the child window's menu item blends the parent Window menu when the child window is running with the focus and maximized.

The way to create a parent window and a child window menu is similar to creating a normal form menu, as detailed in the first chapter. Menu Fusion refers to the interaction between submenus and parent window menus during program operation. When the child window has the focus, the child window's menu or the menu that is inserted into the main window, or some or all of the parent window menus are replaced.

Two properties to set for menu Fusion:

Form's Menu Property

Groupindex Properties for menu items

The Menu property defines the active menu of the form, and the menus merge only on the active menu. If a form has more than one menu part, the runtime can change it with the following code:

Form1.menu: = Secondmenu;

The Groupindex property determines the location of the menu items that appear in the menus bar, and in the menu blending, Groupindex will

Determines whether the Fusion menu inserts or replaces the menu in the main form menu bar.

The default value for Groupindex is 0, and you can determine its value by using the following rule:

1. The smaller the value, the more the menu position is left.

For example, a menu with Groupindex 0 will appear on the leftmost side of the menu bar. As the number of groupindex increases, the menu items are ordered to the right.

2. If you want to replace a menu item in the main menu, set the Groupindex of the corresponding menu item to the same value as the submenu. This rule fits one or more menu items. For example, the Groupindex value of the Edit menu item in the main menu is 1. To set the Groupindext value of one or more menu items for a submenu to 1, these menu items replace the main window's Edit menu at run time.

Sets the Groupindex of multiple menu items of the same form to the same value, and the original order is maintained when the menu is merged

No change.

3. To insert a menu item when the menu is merged, you reserve the value "position" in the main menu. For example, the two-item value for the main menu is 0, 5, and the menu with the submenu Groupindex value of 1,2,3,4 will be inserted when it blends.

When using the MDI interface, users typically open multiple forms. In order for the user to easily switch forms, there is a permanent menu item to toggle. This menu lists the name of the open form, and when the user selects one of them, the program switches the form accordingly. This function can be implemented very conveniently in Delphi's MDI design. The method is to set the windowmenu of the parent window to the name of the menu item.

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.