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

Get Cursor position in TRichEdit

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.