[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Detecting modified lines in richedit control

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 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