We help IT Professionals succeed at work.

TRicjEdit col/row

neostudio
neostudio asked
on
am i missing something ??


procedure Teditor.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
var
  Row, Col: Integer;
begin
  Row := SendMessage(area.Handle, EM_EXLINEFROMCHAR, 0, area.SelStart + area.SelLength);
  Col := area.SelStart + area.SelLength -  SendMessage(area.Handle, EM_LINEINDEX, -1, 0);
  bar.panels[2].Text := IntToStr(Row+1)+ ' ' + IntToStr(Col+1) + ' ' + DateTimeToStr(Now);

end;



i am trying to get row/col/linenumber in a simple richedit called AREA !!


thasnks in advance
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004
Commented:
hi,

a little sample

unit re_caretpos_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    RichEdit1: TRichEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses richedit; //richedit is used
{$R *.DFM}

function GetCaretPos(R : TRichedit) : TPoint;
begin
  if assigned(r) then
  begin
    Result.y := R.Perform(EM_EXLINEFROMCHAR,0,R.SelStart);
    Result.x := R.SelStart - R.Perform(EM_LINEINDEX,Result.Y,0);
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var P : TPoint;
begin
  //+1 only for one-based counting, default is zerobased
  P := GetCaretPos(Richedit1);
  ShowMessage('Row: '+IntToStr(P.y+1)+
             ' Column: '+IntToStr(P.x+1));
  //on d5 you can simply use the CaretPos-property
  ShowMessage('Row: '+intToStr(Richedit1.CaretPos.y+1)+
             ' Column: '+IntToStr(Richedit1.CaretPos.x+1));
end;

end.


meikl ;-)

Author

Commented:
Testing............

Explore More ContentExplore courses, solutions, and other research materials related to this topic.