获取Richedit当前光标处的词

I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
获取Richedit当前光标处的词
uses
RichEdit;
 
procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
Pt: TPoint;
s: string;
begin
with TRichEdit(Sender) do
begin
Pt := Point(X, Y);
// Get Character Index from word under the cursor
iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
if iCharIndex < 0 then Exit;
// Get line Index
iLineIndex := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
if Lines.Count - 1 < iLineIndex then Exit;
// store the current line in a variable
s := Lines[iLineIndex];
// Search the beginning of the word
i := iCharOffset + 1;
while (i > 0) and (s <> ' ') do Dec(i);
// Search the end of the word
j := iCharOffset + 1;
while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
// Display Text under Cursor
Caption := Copy(s, i, j - i);
end;
end;
 

Similar threads

I
回复
0
查看
527
import
I
I
回复
0
查看
499
import
I
I
回复
0
查看
720
import
I
I
回复
0
查看
667
import
I
I
回复
0
查看
606
import
I
顶部