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

Source: Internet
Author: User

4.2 Multi-page interface

The Multi-page interface is a very friendly interface form. It consists of a form and multiple pages, and the information about each page is listed on the label (Tabs) at the bottom of the form, and the user can toggle the page by selecting a label. Only one page is displayed in the form at a time. MPI is more convenient to use than MDI and has a faster switching speed. This chapter routines are examples of a multiple-page interface. In addition, the Code Editor in Delphi Integrated Development Environment (Editor) Form is an example of MPI application in text editing. In MPI, multiple files in a single window can be easily switched and exchanged for data.

Multi-page interface is divided into static MPI and dynamic MPI two kinds of forms. Static MPI has a fixed number of tags, the user in the previous design of multiple pages to switch. The Image Selection dialog box (option Dialog) belongs to the static MPI. Dynamic MPI The number of labels is not fixed, by the program according to the needs of the dynamic production or elimination, like code editing form is dynamic MPI, the program can be based on the needs of users to produce multiple text pages, can also dynamically close the page. The static MPI can be designed conveniently by using Delphi Tnotebook and Ttabset. The design of dynamic MPI requires the writing of specialized code.

4.2.1 Static multi-page interface

Tnotebook,ttabset can be used to develop a static, multiple-page interface. The Tnotebook widget can display multiple pages, each with a corresponding control. Usually the Tnotebook is controlled in conjunction with Ttabset. Ttabset has a set of horizontal labels, each of which can be controlled by creating a list of strings.

The main form in the Mpiedit routine has a tnotebook part and a ttabset part. Set the Aglin property of the two parts to Bstop and Bsbotton, so that they are in the upper and lower parts of the form respectively. To enable Ttabset to work with Tnotebook, use the following code:

Tabset1.tabs: = Notebook1.page;

In addition, the following code is defined in the Tabset onclick event to enable the user to fight the corresponding page when selecting a label.

Procedure Teditform.tabsetclick (Sender:tobject);

Begin

Notebook1.pageindex: = Tabset1.tabindex;

...

End

When designing static MPI, the WIN3 of the part form (Component Palette) can be used. 1 page Select the Tnotebook part, and then in the Object Inspector form, double-click the Tnotebook pages property, Dephi will pop-up dialog box, where the user can determine the number of notebook page and string list, as shown in Figure 4.6. When you close the dialog box, you can design each page and use the right mouse button to eject the Quick menu for page switching.

4.2.2 Dynamic Multi-page interface

It is very simple to use Delphi for static MPI design, so it is necessary to write special code for dynamic MPI design. Right

In a multiple-page text editor, the following features should be implemented:

Dynamically generate pages, each page can be edited for text

Close the page dynamically until there is only one page in the form

Page transitions do not affect various text editing operations

To achieve these functions, a dynamic page class (Tdynapage) is used in the program, which is defined as follows:

Type Tdynapage = Class (TObject);

The class can dynamically generate pages as needed, and tmeno parts that can be edited for text are created on each page.

Procedure ...

Puclic

Curpage:integer;

Filelist:tsringlist;

End

Curpage represents the number of pages selected by the current user, and the user switching, adding, and deleting pages all affect the Curpage value, curpage at first as 0 pages. FileList stores the names of the files that are opened or created and the editing parts associated with them TMemo, dynamically creating and deleting pages will affect filstlist values.

The Tnotebook part is created with at least one page, so the pages property is not null, and as long as you add a string to pages, Delphi automatically ties the string to the Tpage class object. The Tpage class is derived from Tcustomedit, and tpage data members and methods can be observed in the Object Browser. Statically generated pages are also tpage classes.

To create a multiple-page editor, you must create a corresponding edit part from the parent part of the tpage. But when creating a page dynamically, Tpage is just a tobject class that is associated with a string and cannot be written as:

Memoparent: = notebook1.pages.object[];

In Delphi, declaring objects and creating objects are identified by pointers, so pointers can be passed with no type pointers.

Var

Pi:pointer;

Begin

Pi: = notebook1.pages.object[];

Memo.parent: = Pi;

End

This allows you to dynamically create editorial pieces on the Tpage.

When the page is dynamically generated in the NOTEBOOK1, the page should be switched and tdynapage. Notebook1.tabset1 related properties should be adjusted accordingly.

The Tdynapage Dynaadd method is defined as follows:

Procedure Tdynapage.dynaadd (Sender:tnotebook; filename:string);

Var

Pi:pointer;

Memo:tmemo;

Begin

Sender.Pages.add (FileName);

Pi:= Sender.pages.objects[sender.pages.count-1];

Dynamemo (PI);

DynaPage.FileList.addObject (FILENAME,MEMO1);

EditForm.TabSet1.Tabs: = sender.pages;

editform.tabset1.tabindex:=sender.pages.count-1;

EditForm.Notebook1.PageIndex: = EditForm.Tabset1.TabIndex;

Dynapage.curpage:= sender.pages.count-1;

End

Procedure Dynamemo (Pi:pointer);

Var

Memo:tmemo;

Begin

Memo:=tmemo.create (Pi);

Memo.parent:=pi;

Memo.align:=alclient;

Memo.borderstyle:=bsnone;

Memo.hideselection:=false;

Memo1:=memo;

End

Procedure Tdynapage.del (Sender:tnotebook; No:integer);

Var

Pi:pointer;

Begin

Sender.Pages.delete (No);

EditForm.TabSet1.Tabs.delete (No);

Filelist.delete (No);

Dynapage.curpage:=editform.tabset1.tabindex;

Sender.pageindex: = EditForm.Tabset1.TabIndex;

Pi:=filelist.objects[dynapage.curpage];

Memo1:=pi;

Editform.caption:=sender.pages.strings[dynapage.curpage];

End

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.