Google
 

Tuesday, October 23, 2007

Get Cursor position in TRichEdit

Here's how to determine the *current* Row and Col of a cursor in a RichEdit... ~~~~~~~~~~~~~~~~~~~~~~~~~

//Usage:

var sRC:string;

src := GetPosition(RichEdit1) ;
//src reults in a string
//formated like: Row:Col


function GetPosition(ARichEdit: TRichEdit): string
var
iX,iY : Integer;
begin
iX := 0; iY := 0;
iY := SendMessage(ARichEdit.Handle,
EM_LINEFROMCHAR,
ARichEdit.SelStart,0) ;
iX := ARichEdit.SelStart -
SendMessage(ARichEdit.Handle,
EM_LINEINDEX, iY, 0) ;

Result := IntToStr(iY + 1) + ':' + IntToStr(iX + 1) ;
end;

~~~~~~~~~~~~~~~~~~~~~~~~~

No comments: