procedure TForm1.Memo1Click(Sender: TObject);
begin
  Text := Format('当前列:%d, 当前行:%d', [Memo1.CaretPos.X, Memo1.CaretPos.Y]);
end;

//用 API 实现
procedure TForm1.Memo1Click(Sender: TObject);
var
  LineY,LineX: Integer;
begin
  LineY := SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0);
  LineX := SendMessage(Memo1.Handle,EM_LINEINDEX,LineY,0);
  Text :=  '当前行:' + IntToStr(LineY) + '; ' +                  //0开始
          '当前列:' + IntToStr(Memo1.SelStart - LineX) + '; ' +   //0开始
          '当前字符:' + IntToStr(Memo1.SelStart) + '. ';          //包括#13#10
end

 

 

posted on 2010-10-29 20:51  巅枫  阅读(330)  评论(0编辑  收藏  举报