如何取得richedit中鼠标所指处的文字(0分)

  • 主题发起人 主题发起人 孤星2005
  • 开始时间 开始时间

孤星2005

Unregistered / Unconfirmed
GUEST, unregistred user!
如何取得richedit中鼠标所指处的文字
 
PFans (2001-11-5 10:27:00)
-------------------------------------------------------
在Public中加入
function IsSeparetor(ch:char):Boolean; //判定一个字符是否为分隔符
function GetWord(Pos:word): String; //读取鼠标所在位置的单词

实现上面两个函数:
function IsSeparetor(ch:char):Boolean;
begin
IsSeparetor:=false;
if ch in [' ',',','.','、',#10,#13] then
IsSeparetor:=true;
end;

function GetWord(Pos:word): String;
begin
w:=''; pos:=1;getword:='';
//读取文本框中的内容
st:=Memo1.Lines.Text;
pos2:=length(st);
//向前搜索当前单词起始位置
for i:=pos-1 down to 1 do
if IsSeparetor(St) then
begin
pos1:=i+1;break;
end;
//向后搜索当前单词起始位置
for i:=pos to pos2 do
if IsSepatetor(St) then
begin
pos2:=i-1;break;
end;
//截取pos1--pos2之间的字符,形成一个单词
if pos1<=pos2 then
begin
for i:=pos1 to pos2 do
w:=w+st;
GetWord:='单词:'+w;
end;
end;

Memo1MouseMove事件
var
lc:longint;
charPos:word;
begin
lc:=SendMessage(Memo1.handle,EN_CHARFROMPOS,0,X+(Y shl 16));
Memo1.Hint:=GetWord(CharPos);
end;

FormCreate事件
begin
Memo1.ShowHint:=True;
end;
 
to zw84611:
lc怎么没有用到呀
 
后退
顶部