Solved

Detecting modified lines in richedit control

Posted on 2001-07-21
3
297 Views
Last Modified: 2013-11-22
I'm writing an application which uses TRichEdit.
When an user modifies anything in a richedit control an OnChange event is launched. What I need is to detect which lines were actually modified by the user.
In most cases this is easy, as the line modified is the same where the caret is. The problem is when someone pastes 2 or more lines of text, or drag-drops a selection of text...

How can I do this?

Thanks
0
Comment
Question by:wizcool
3 Comments
 
LVL 5

Accepted Solution

by:
alanwhincup earned 200 total points
ID: 6306319
Try this:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    Label1: TLabel;
    procedure RichEdit1Enter(Sender: TObject);
    procedure RichEdit1KeyPress(Sender: TObject; var Key: Char);
    procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RichEdit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  PreLine : Integer;

implementation

{$R *.DFM}

procedure TForm1.RichEdit1Enter(Sender: TObject);
begin
  PreLine := RichEdit1.CaretPos.Y + 1;
end;

procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  PreLine := RichEdit1.CaretPos.Y + 1;
end;

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  PreLine := RichEdit1.CaretPos.Y + 1;
end;

procedure TForm1.RichEdit1Change(Sender: TObject);
var
  LineChanged : Integer;
begin
  LineChanged := RichEdit1.CaretPos.Y + 1;
  if PreLine = LineChanged then
    Label1.Caption := 'Line Changed: ' + IntToStr(LineChanged);
  if PreLine > LineChanged then
    Label1.Caption := 'Lines Changed: ' + IntToStr(LineChanged) + ' - ' + IntToStr(PreLine);
  if PreLine < LineChanged then
    Label1.Caption := 'Lines Changed: ' + IntToStr(PreLine) + ' - ' + IntToStr(LineChanged);
  PreLine := LineChanged;
end;

end.

Cheers,

Alan
0
 
LVL 1

Expert Comment

by:filipecorreia
ID: 6309913
;)
0
 

Author Comment

by:wizcool
ID: 6310316
That worked fine, although I had to change the "TForm1.RichEdit1KeyPress" to "keyup" as the "keypress" event doesn't trigger when the cursor keys are pressed...

Thanks ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now