如何得到文本控件光标处的单词

解决方案 »

  1.   

    你是说屏幕取词吗?
    有问题请发信息到我的E-mail:[email protected]
      

  2.   

    function JCharIndexByPos(RichEdit: TRxRichEdit;X, Y: Integer): Integer;
    var
     P : TPoint;
    begin
      P := Point(X, Y);
      Result := SendMessage(RichEdit.Handle, EM_CHARFROMPOS, 0, LongInt(@P));
    end;function JExtractWordFromPos(RichEdit: TRxRichEdit; X, Y: Integer;
                                  var iBegPos, iEndPos : Integer): string;
    //var
    //  iBegP, iEndP : Integer ;
    begin
      iBegPos := JCharIndexByPos(RichEdit, X, Y);//  ShowMessage(IntToStr(iBegPos)) ;
      if (iBegPos < 0) or
         (SendMessage(RichEdit.Handle, EM_FINDWORDBREAK, WB_CLASSIFY, iBegPos)
         and (WBF_BREAKLINE or WBF_ISWHITE) <> 0 ) then
      begin
        Result := '' ;
        Exit;
      end;
      if SendMessage(RichEdit.Handle, EM_FINDWORDBREAK, WB_CLASSIFY, iBegPos - 1)
         and (WBF_BREAKLINE or WBF_ISWHITE) = 0 then
        iBegPos := SendMessage(RichEdit.Handle, EM_FINDWORDBREAK,
                   WB_MOVEWORDLEFT, iBegPos) ;
     iEndPos := SendMessage(RichEdit.Handle, EM_FINDWORDBREAK,
                WB_MOVEWORDRIGHT, iBegPos) ;
     Result := TrimRight(JGetTextRange(RichEdit, iBegPos,
               iEndPos - iBegPos)) ;
    end;
    就是JExtractWordFromPos,不知道是不是你要用的?
      

  3.   

    举手之劳:么TMemo例子
    var LineNum:longint;
        CharsBeforeLine:longint;
        row,col:string;
    begin
    LineNum:=SendMessage(Memo.Handle,EM_LINEFROMCHAR,Memo.SelStart,0);
    CharsBeforeLine:=SendMessage(Memo.Handle,EM_LINEINDEX,LineNum,0);
    row:='Row:'+IntToStr(LineNum+1);
    col:='Col:'+IntToStr((Memo.SelStart-CharsBeforeLine)+1);