Buscar

Extraindo palavra que está sob o cursor

Código

Function RECharIndexByPos(RichEdit: TRichEdit; X, Y: Integer): Integer;
{ retorna a posição absoluta do caracter para um conjunto de coordenadas do cursor}
var
P: TPoint;
begin
P := Point(X, Y);
Result := SendMessage(RichEdit.Handle, EM_CHARFROMPOS, 0, longint(@P));
end;
 
function REExtractWordFromPos(RichEdit: TRichEdit; X, Y: Integer): string;
{ X, Y - coordenadas num controle rich edit }
{retorna a palavra sob a posição corrente do cursor}
var
BegPos, EndPos: Integer;
begin
BegPos := RECharIndexByPos(RichEdit, X, Y);
if (BegPos < 0) or
(SendMessage(RichEdit.Handle,EM_FINDWORDBREAK,WB_CLASSIFY,BegPos) and
(WBF_BREAKLINE or WBF_ISWHITE) <> 0 ) then
begin
result:='';
exit;
end;
if SendMessage(RichEdit.Handle, EM_FINDWORDBREAK, WB_CLASSIFY, BegPos- 1) and
(WBF_BREAKLINE or WBF_ISWHITE) = 0 then
BegPos := SendMessage(RichEdit.Handle, EM_FINDWORDBREAK,
WB_MOVEWORDLEFT, BegPos);
EndPos := SendMessage(RichEdit.Handle, EM_FINDWORDBREAK,
WB_MOVEWORDRIGHT, BegPos);
Result := TrimRight(REGetTextRange(RichEdit, BegPos, EndPos - BegPos));
end;

Publicidade

Vote na dica




Quantidade de votos: 0 votos
Aceitação: 0%


Detalhes da dica

Categoria: Periféricos
Adicionada dia: 20/06/03
Por: Felipe Monteiro
Visualizada: 3079 vezes

Planeta Delphi - Tudo sobre programação Delphi Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009