View Issue Details

IDProjectCategoryView StatusLast Update
0025666LazarusLCLpublic2016-12-25 15:20
ReporterSergey Bulba Assigned ToBart Broersma  
Status closedResolutionfixed 
Product Version1.2.0RC2 
Summary0025666: Wrong TEdit.Modified behavior?
DescriptionIn my old programs on Delphi I'd used "TEdit.Modified" property to detect kind of changing: manual (typing from keyboard) or run-time (Edit1.Text := 'some text').
Steps To ReproducePlace Edit1 on Form1 in new project and write OnChange handler like:

procedure TForm1.Edit1Change(Sender: TObject);
if Edit1.Modified then
   //Section1: do analysis of manual Edit1.Text changing
  //Section2: was programmatic changing like Edit1.Text := 'some text'

to ensure, that Section2 is never run in Lazarus, only in Delphi
Additional InformationOf course, it can be Delphi bug, and I must fix my old programs instead of Lazarus-bug reporting :) Sorry, if it is...
TagsNo tags attached.
Fixed in Revisionr45617
Attached Files


Bart Broersma

2014-02-03 19:01

developer   ~0072836

Last edited: 2014-02-03 19:27

View 3 revisions

You might be right.

"Use Modified to determine whether the user changed the Text property of the edit control. Modified is only reset to False when you assign a value to the Text property. In particular, it is not reset when the control receives focus."

Text := SomeText -> RealSetText -> triggers TextChanged -> sets Modified to True -> after that Modified is set to False in RealSetText.

Maybe need to set a flag in RealSetText, so we can set Modified to false in TextChanged?
Feels a bit hackish to me.

Sergey Bulba

2014-02-05 10:36

reporter   ~0072854

This bug can cause a stack overflow because of recursive calls of TEdit.OnChange. For example, if we want modify user input "on the fly", due Modified is always True, recursive calls can stop only after new and old Text of TEdit will be identical, it is work in most cases, except like this:

procedure TForm1.Edit1Change(Sender: TObject);
  if Edit1.Modified then
   Edit1.Text := IntToStr(StrToInt(Edit1.Text) + 1);

If you press any number key in Edit1, you'll see overflow error. In Delphi 7 this example works as expected (without error).

Bart Broersma

2014-02-05 10:59

developer   ~0072855

I understand it is a bug, no need to keep pointing it out.
Just not sure what is the best way to solve it.

If you desperately need it NOW, then do something like this:

(file /lcl/
In TCustomEdit.RealSetText:
Set a boolean flag (first declare it as a private field of TCustomEdit in stdctrls.pp)
Set modified := False _before_ the call to inherited RealSetText

In TCustomEdit TextChanged:
Do not set Modified to True if the flag is True
Reset the flag to False.

Rebuild your app, it'll rebuild the lcl.
This should (in theory) fix it.

Bart Broersma

2014-02-09 17:12

developer   ~0072969

> Maybe need to set a flag in RealSetText, so we can set Modified to false in
> TextChanged?

This will make Modified = False in TMaskEdit always, so that won't do.

Bart Broersma

2014-02-20 18:44

developer   ~0073178

Unassigning, don't see a quick solution.

Bart Broersma

2014-06-22 18:39

developer   ~0075849

Please test and close if OK.

Sergey Bulba

2016-12-25 15:20

reporter   ~0097075

Thanks, just tested

Issue History

Date Modified Username Field Change
2014-02-03 12:36 Sergey Bulba New Issue
2014-02-03 19:01 Bart Broersma Note Added: 0072836
2014-02-03 19:25 Bart Broersma Note Edited: 0072836 View Revisions
2014-02-03 19:27 Bart Broersma Note Edited: 0072836 View Revisions
2014-02-03 19:28 Bart Broersma LazTarget => -
2014-02-03 19:28 Bart Broersma Status new => confirmed
2014-02-05 10:36 Sergey Bulba Note Added: 0072854
2014-02-05 10:59 Bart Broersma Note Added: 0072855
2014-02-05 16:58 Bart Broersma Assigned To => Bart Broersma
2014-02-05 16:58 Bart Broersma Status confirmed => assigned
2014-02-09 17:12 Bart Broersma Note Added: 0072969
2014-02-20 18:44 Bart Broersma Note Added: 0073178
2014-02-20 18:44 Bart Broersma Assigned To Bart Broersma =>
2014-02-20 18:44 Bart Broersma Status assigned => acknowledged
2014-06-22 18:39 Bart Broersma Fixed in Revision => r45617
2014-06-22 18:39 Bart Broersma Note Added: 0075849
2014-06-22 18:39 Bart Broersma Status acknowledged => resolved
2014-06-22 18:39 Bart Broersma Resolution open => fixed
2014-06-22 18:39 Bart Broersma Assigned To => Bart Broersma
2016-12-25 15:20 Sergey Bulba Note Added: 0097075
2016-12-25 15:20 Sergey Bulba Status resolved => closed