Solved

Detecting modified lines in richedit control

Posted on 2001-07-21
3
293 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 168
Delphi selector screen 2 58
Multiple image collision 13 46
Adoquery sql  left join does not work 25 51
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

12 Experts available now in Live!

Get 1:1 Help Now