这是个有意思的问题我钻研了一下API,终于找到了解答:
用下面这个函数:
procedure TForm1.getxy(var i,j :integer);
var
iIndex :Integer;
begin
i := SendMessage(Memo1.handle,em_lineFromChar,-1,0);
iindex :=SendMessage(Memo1.handle,em_lineindex,i,0);
j := Memo1.selstart+Memo1.SelLength-iindex;
end;
程序中调用他就可以了。
eg:
procedure TForm1.Button2Click(Sender: TObject);
var
i,j :integer;
begin
getxy(i,j);
ShowMessage(Format('row=%d,col=%d',[i,j]));
end;