1. Home
  2. Computing & Technology
  3. Delphi Programming

Get Cursor position in TRichEdit

By Zarko Gajic, About.com

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;

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

Delphi tips navigator:
» Associate an application with a file extension
« Implementing a lasso drawing technique

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Get Cursor position in TRichEdit

©2009 About.com, a part of The New York Times Company.

All rights reserved.