The memo in Delphi displays the line number column number

Source: Internet
Author: User

Http://www.alonely.com.cn/Delphi/20160814/8912.html

Examples illustrate this example is a simple technique for cursor application, and I hope that this example can be extrapolate after learning. Delphi like this simple and practical examples there are many, as long as the usual more attention to accumulate can write concise, efficient code execution. Programming ideas send a message directly to the memo component Em_linefromchar and detect the return value, you can learn the line number of the cursor in this component, send a message to the memo component Em_lineindex and detect the return value to know the column number of the cursor in this component

Example description

This example is a simple technique for cursor application, and hopefully it will be extrapolate after learning from this example. Delphi like this simple and practical examples there are many, as long as the usual more attention to accumulate can write concise, efficient code execution.

Programming IdeasSend a message Em_linefromchar directly to the memo component and detect the return value to know the line number of the cursor in this component, send a message to the memo component Em_lineindex and detect the return value to learn the column number of the cursor in this component.

Programming StepsFirst put three label components on the form and declare the following three variables as integers in front of the program code, namely: Varlpos,cpos,linelength:integer; where Lpos is the value of the row (according to the memo, the first act O), CPOs is the position of the character, LineLength is the total number of characters in the current line. Then, add the following seven lines of program code to MEMO1 's onmousedown and OnKeyDown's event code respectively. Lops:=sendmessage (memo1.handle,em_linefromchar,memol.selstart,0); Cpos:=sendmessage (menol.handle,em_lineindex,lpos,0); Linelength:=sendmessage (memol.handle,em_linelength,cpos,0); Cpos:=memol.selstart-cpos; Label1.caption:=inttostr (IPOs); Label2.caption:=inttostr (CPOs); Label3.caption:=inttostr (linelength); When you are finished, as you execute the program, Labell, Label2, and LABEL3 will show the total number of characters corresponding to the current line value, the character position, and the current line as you edit the memo component.

Programming SummaryPlease join the "Get the line number of the cursor in the RichEdit component" to learn together, in fact the two are very similar. attach another article:

First, how to know the current line number
When you make a text editor with the RichEdit (or Memo) control, you can get the total number of rows by accessing the lines Count property, but it is troublesome to know the line number of the current line of the cursor, because Delphi does not provide this attribute. To implement this editor-required feature, you must call Em_ Linefromchar. Please try the following program.
First place a RichEdit or memo (named editor) in the window, and a button. Write the following code in the OnClick event of the button.
Var
Currentline:integer;
Begin
Currentline:=editor Perform (em_ linefromchar,sffff,0);
Application MessageBox (PChar (the current line number is ′+INTTOSTR (CurrentLine)), the message ′,mb_ iconinformation);
End
Note that the line number of the first line is zero.
Second, how to undo the operation (undo)
For memo, the implementation of undo is not programming, as long as the PopupMenu property is empty, the runtime can use the right mouse button to activate a common menu of actions, including undo, Cut, copy, paste, delete and select all six items.
But unfortunately, this trick for powerful RichEdit control actually does not work, harm we also have to design a popupmemu. When you use Cuttoclipboard and other statements to easily and smoothly complete the "cut" and other functions, then will be helpless to find that the undo or cancel and other statements to perform "Undo."
At this point you need to deal with:
RichEdit1 Perform (em_undo,0,0);
You should also check whether undo is allowed to turn on or off the undo item in the pop-up menu:
Undo1 enabled:=richedit Perform (em_canundo,0,0) <>0;
The above program is debugged in Delphi3.

The memo in Delphi displays the line number column number

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.