1. How to get the current line number
When using the RichEdit (or memo) control to make a text editor, you can get the total number of lines by accessing the lines??count attribute. However, it is troublesome to know the line number of the line where the cursor is currently located, because Delphi does not provide this attribute. To implement this essential editor function, em_ LineFromChar must be called. Please try the procedure below.
First arrange a RichEdit or memo (named editor) and a button in the window. Write the following code in the button's onclick event.
var
CurrentLine:Integer;
begin
CurrentLine:=Editor??Perform(em_ LineFromChar,SFFFF,0);
application??MessageBox(PChar('The current line number is'+IntToStr(CurrentLine)),'Message',mb_ iconinformation);
end;
Note that the first line has a line number of zero.
2. How to undo an operation (undo)
For memo, no programming is required to implement undo. As long as the popupmenu attribute is empty, a common operation menu can be activated with the right mouse button during runtime, including six items: undo, cut, copy, paste, delete and select all. .
But unfortunately, this method does not work for the powerful RichEdit control, so we have to design a popupmemu ourselves. When you use CutToClipBoard and other statements to easily and smoothly complete functions such as "cut", you will be helpless to find that you can't find statements such as undo or cancel to perform "undo".
At this time you need to handle it like this:
RichEdit1??Perform(EM_UNDO,0,0);
You should also check whether undo is allowed, thereby turning on or off the "Undo" item in the pop-up menu:
Undo1??Enabled:=RichEdit??Perform(EM_CANUNDO,0,0)<>0;
The above program passed debugging in Delphi3