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

Source: Internet
Author: User
Tags count

When a user switches through multiple pages, the program should ensure that the current page is edited. For example, in a multi-page editor, the user selects a page to edit, search for, set up, print, and so on the file in the page. To achieve this, a variable of type TMemo is defined: MEMO1, the variable is not instantiated, and each invocation of the Dynaadd,dynadel method assigns TabIndex the memo pointer to the specified page to Memo1. In this way, there is always an instantiated memo pointer assigned to MEMO1 in the program, and the text editing function in the menu operates on the Memo1. This kind of pointer pass guarantees that the current page will be manipulated.

After defining the tdynapage, simply add the following code to the Open,close menu item to easily create a delete page when the user opens the closed file.

Procedure Teditform.close1click (Sender:tobject);

Begin

If Dynapage.curpage<>0 Then

Dynapage.del (Notebook1,dynapage.curpage);

If Notebook1.Pages.count = 1 Then

Close1.enabled:=false;

End

Procedure Teditform.open1click (Sender:tobject);

Begin

If Opendialog1.execute Then

Begin

If not (OpenFile or NewFile) then

Begin

Openfile:=true;

Open (Opendialog1.filename);

Notebook1.pages.strings[0]:=extractfilename (Opendialog1.filename);

Tabset1.tabs:=notebook1.pages;

End

Else

Begin

Dynapage.dynaadd (Notebook1, Extractfilename (opendialog1.filename));

Open (Opendialog1.filename);

If Notebook1.Pages.count > 1 Then

Close1.enabled:=true;

End

End

End

4.3 text editorial part and its application

4.3.1 Tedit Parts

The Tedit widget is a standard edit box that allows users to enter data in the edit box. The edit box can also display data to the user. You can read and write only one line of information while editing.

The Tedit Text property holds the data entered by the user or displayed to the user, and the modified property is used to identify whether the data of text changes, and you can limit the number of user input characters by setting the MaxLength property value Charcase

property to define the case of the characters in the edit box. If the designer wants to prevent user input, set the ReadOnly property to a truth value. The edit box can also be used as a password entry box. By setting the value of the PasswordChar property, you can display the character entered by the user in the edit box as the specified character, such as the "*" number. The edit box can also perform character selection operations, paste, copy, and cut operations.

4.3.2 TMemo Parts

The TMemo part is similar to the Tedit part, can display the data to the user, the user can also enter the data. and Tedit Parts

The difference is that the TMemo part can handle multiple lines of text and is used primarily for editing files.

The TMemo Text property can be accessed only at run time. Modified property to identify text whether the data is changed

To restrict the number of user input characters by setting the MaxLength property value.

If you are accessing text as a whole, use the Text property, or you can use the Lines property if you want to access it on a line-by-row basis. The Lines property makes it easier to access files. Lines is a tstrings type, so you can use the Add, delete method, such as the code to include a line of strings in Memo1 as follows:

MEMO1.LINES.ADD (' Another line is added ');

The Lines property makes it easy to read a file into a part, and the following code is used in the routine to read the file into Memo1:

Memo1.Lines.loadFromFile (Filename).

It is convenient to cut, copy, and paste text from the TMemo part simply by using the Cuttoclipboard, Copytoclipbroad,pastefromclipboard method, whose code is as follows:

Memo1.copytoclipboard

Memo1.cuttoclipboard

Memo1.pastefromclipboard

TMemo has some properties that control the display of text. The ScrollBars property can define the horizontal and vertical scroll bars of a part. When file fonts change, use the AutoSize property to adjust the size of the parts accordingly. Setting the WordWrap property allows wrapping to be done automatically.

Routines in edit| The WordWrap menu item provides the ability to set the WordWrap and can determine the form of a scrollbar based on the value of WordWrap. When WordWrap is true, the horizontal scroll bar is not required and the check mark is made in the menu.

The code is as follows:

Procedure Teditform.setwordwrap (Sender:tobject);

Begin

With Memo1 do

Begin

WordWrap: = Not wordwrap;

If WordWrap Then

ScrollBars: = Ssvertical Else

ScrollBars: = Ssboth;

wordwrap1.checked: = WordWrap;

End

Seteditrect;

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.