DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

MemoCursorPos

Returns a TPoint value containing the coordinates of the cursor in the given memo control.

function MemoCursorPos(const Memo: StdCtrls.TCustomMemo): Windows.TPoint;
var
  Row, Col: Integer;  // row and column containing cursor
begin
  Row := Windows.SendMessage(
    Memo.Handle, Messages.EM_LINEFROMCHAR, Memo.SelStart, 0
  );
  Col := Memo.SelStart - Windows.SendMessage(
    Memo.Handle, Messages.EM_LINEINDEX, Row, 0
  );
  Result.X := Col;
  Result.Y := Row;
end;

View the whole database.

Go to the DelphiDabbler website.