我是这样用的:  var
    iline:integer;
  begin
    iline:=richedit.perform(em_linefromchar,$ffff,0);
  end;
 而结果是:获取的是总行数,如何获取鼠标所在位置的行号呢!!!!!用memo就没有问题!为什么?

解决方案 »

  1.   

    //如果你用的是Delphi6就直接用CaretPos这属性即可
    //否则参考如下VCL
    function TCustomMemo.GetCaretPos: TPoint;
    begin
      Result.X := LongRec(SendMessage(Handle, EM_GETSEL, 0, 0)).Hi;
      Result.Y := SendMessage(Handle, EM_LINEFROMCHAR, Result.X, 0);
      Result.X := Result.X - SendMessage(Handle, EM_LINEINDEX, -1, 0);
    end;
      

  2.   

    /********************************
    pp,ll:integer;
       pp:=RichEdit1.CaretPos.x;
       ll:=RichEdit1.CaretPos.y;
        showmessage(inttostr(pp));
       showmessage(inttostr(ll));
    //********************************
      

  3.   

    RichEdit中的行号是以0开头的,所以应该这样做: Edit1.Text:= IntToStr(RichEdit1.CaretPos.Y = 1);
      

  4.   

    var
      iCharIndex, iLineIndex : Integer;
      Pt : TPoint;
    begin
        Pt := Point(X, Y);
        iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
        if iCharIndex < 0 then Exit;
        iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
        //iLineIndex 就是你要的行
        *******end;