Solved

Detecting modified lines in richedit control

Posted on 2001-07-21
3
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 167
select query - oracle 16 101
Firemonkey android show image from resource ? 1 56
How to build JSON File in Delphi 6 3 71
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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