?
Solved

Detecting modified lines in richedit control

Posted on 2001-07-21
3
Medium Priority
?
327 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 800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

765 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