2009. június 15., hétfő

Access the current row/column of a TMemo


Problem/Question/Abstract:

Access the current row/column of a TMemo

Answer:

The following code reads and writes the cursor's position as row and column; counting starts at 0.

procedure GetMemoRowCol(M: TMemo; var Row, Col: LongInt);
begin
  Row := SendMessage(M.Handle, EM_LINEFROMCHAR, M.SelStart, 0);
  Col := M.SelStart - SendMessage(M.Handle, EM_LINEINDEX, Row, 0);
end;

procedure SetMemoRowCol(M: TMemo; Row, Col: Integer);
begin
  M.SelStart := SendMessage(M.Handle, EM_LINEINDEX, Row, 0) + Col;
end;

Nincsenek megjegyzések:

Megjegyzés küldése