View Issue Details

IDProjectCategoryView StatusLast Update
0030425LazarusLCLpublic2017-02-03 09:13
ReporterDmitry D. ChernovAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386-win32OSWindowsOS VersionXP SP3 x86
Product Version1.6Product Build51630 (2016-02-23) 
Target Version1.6.2Fixed in Version1.6.2 
Summary0030425: TDateEdit: DefaultToday doesn't work properly if DirectInput property is False
DescriptionTDateEdit.DefaultToday sets current date only if Text property is empty, but it's impossible to set it empty at design-time if DirectInput option was set to False AFTER DefaultToday was set to True. This caused by auto-setting Text property to the current date if DirectInput was changed with DefaultToday set to True. When DirectInput is False, Text property become read-only - it always restore current date value.

It's possible to remove Text property value directly from the form file, but this will work only before next saving of the form, when Text value will be re-assigned to the date of saving.
Steps To Reproduce1. Create default LCL project.
2. Put TDateEdit onto the form.
3. Set DefaultToday to True.
4. Set DirectInput to False.
5. You will notice that Text value was changed and it's impossible to clear it now.
6. Build the project.
7. Change system date to another one.
8. Run the program. You will notice that TDateEdit value isn't equal to the current system date.
TagsNo tags attached.
Fixed in Revisionr52777, r54070
LazTarget1.6.2
WidgetsetWin32/Win64
Attached Files
  • editbtn.diff (609 bytes)
    Index: lcl/editbtn.pas
    ===================================================================
    --- lcl/editbtn.pas	(revision 52737)
    +++ lcl/editbtn.pas	(working copy)
    @@ -1660,7 +1660,11 @@
           FDate := TextToDate(AValue, SysUtils.Date)
         else
           FDate := TextToDate(AValue, NullDate);
    -    inherited RealSetText(DateToText(FDate));
    +    //Allow to clear Text in Designer (Issue #0030425)
    +    if (csDesigning in ComponentState) and (AValue = '') then
    +      inherited RealSetText('')
    +    else
    +      inherited RealSetText(DateToText(FDate));
       end else
         inherited RealSetText(AValue);
     end;
    
    editbtn.diff (609 bytes)

Activities

Bart Broersma

2016-07-30 14:35

developer   ~0093904

Last edited: 2016-07-30 15:02

View 2 revisions

Would allowing Text to be empty in thisscenario (i.e. in FormDesigner) be an accetable fix?

Please test with attached patch (editbtn.diff).

Bart Broersma

2016-07-30 15:01

developer  

editbtn.diff (609 bytes)
Index: lcl/editbtn.pas
===================================================================
--- lcl/editbtn.pas	(revision 52737)
+++ lcl/editbtn.pas	(working copy)
@@ -1660,7 +1660,11 @@
       FDate := TextToDate(AValue, SysUtils.Date)
     else
       FDate := TextToDate(AValue, NullDate);
-    inherited RealSetText(DateToText(FDate));
+    //Allow to clear Text in Designer (Issue #0030425)
+    if (csDesigning in ComponentState) and (AValue = '') then
+      inherited RealSetText('')
+    else
+      inherited RealSetText(DateToText(FDate));
   end else
     inherited RealSetText(AValue);
 end;
editbtn.diff (609 bytes)

Dmitry D. Chernov

2016-07-30 17:59

reporter   ~0093906

Last edited: 2016-07-30 18:01

View 2 revisions

Tested, thanks.
IMHO, it's not a fix, but silly workaround.

Firtsly, Text will be assigned to the current date anyway after setting DefaultToday=True and DirectInput=False, so problem will occur. It's not obvious for user^W programmer that he also must set Text='' to get the correct behavior.

Secondly, setting Text value is meaningless when DefaultToday=True and DirectInput=False are set. It also may lead to the wrong programming technique when programmer will modify Text value in code by himself at run-time, with DirectInput set to False. And finally, it's nice to see _current_ date at design-time if DefaultToday=True and DirectInput=False.

For me, the right way to fix this, is as follows:
When DefaultToday=True and DirectInput=False,
1) Text is read-only and obligatorily empty at design-time;
2) Component displays current date at design-time.

I'm not sure about (2) - is that possible to display anything at design-time with empty Text? But (1) seems at least legit and must be implemented to fix the problem.

Bart Broersma

2016-07-30 19:07

developer   ~0093908

Last edited: 2016-07-30 19:13

View 3 revisions

> Secondly, setting Text value is meaningless when DefaultToday=True and DirectInput=False are set.

??
In any Edit like control you can programmatically set Text if the control is ReadOnly, and so you can in TDateEdit.
Wether this is the smart thing to do is an entirely different discussion.

> When DefaultToday=True and DirectInput=False,
> 1) Text is read-only and obligatorily empty at design-time;

This is not consistent with other Text like controls.
Even if they are readonly you can still set Text in OI.

With proposed fix you can:
- set DefaultToday = True
- set DirectInput = False
and then
- set Text = '': at program start Date will be Now and Text will be accordingly
- set Text = '31-12-1975': at program start Date will be 31-12-1975

> 2) Component displays current date at design-time.
I don't think this an be achieved.

Dmitry D. Chernov

2016-07-31 03:39

reporter   ~0093910

Okay, got you.
Then I propose next way to fix it:
1) Ability to change Text at design-time in any case, even if DirectInput=False.
2) Text must not be set to the current date when setting DefaultToday=True and DirectInput=False afterwards.

Bart Broersma

2016-07-31 11:11

developer   ~0093911

> 1) Ability to change Text at design-time in any case, even if DirectInput=False.

This was already the case, Text needs to be a valid date. Now Text can be empty as well. In all other cases it will be reset to "Now".

2) Text must not be set to the current date when setting DefaultToday=True and DirectInput=False afterwards.

I disagree: the rules I stated at point 1 must apply.
The cooments in the code explain the design philosophy behind this:
//Synchronize FDate and force valid text

Dmitry D. Chernov

2016-08-02 05:34

reporter   ~0093956

About rules at point 1:

> This was already the case, Text needs to be a valid date. Now Text can be empty as well. In all other cases it will be reset to "Now".

But it breaks the principle of least astonishment if Text can be changed programmatically at run-time, is not it so?

Bart Broersma

2016-08-02 18:29

developer   ~0093967

No it does not.
ReadOnly means the control cannot be altered by the user, where user = the person using the compiled software.
It never meant that the developer could not alter the Text at designtime, nor did it mean that Text could not be set programmatically.

Bart Broersma

2016-08-02 18:33

developer   ~0093968

Applied proposed fix in r52777.
Please close.

Dmitry D. Chernov

2016-08-02 19:08

reporter   ~0093972

Well, then I propose to add note to the description of DefaultToday property that this will work ONLY if Text is not set.

Bart Broersma

2016-08-02 19:41

developer   ~0093973

Last edited: 2016-08-02 19:43

View 2 revisions

F1 on DefaultToday (in OI) opens http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/tdateedit.defaulttoday.html

"DefaultToday - if True, the current date is offered as the default date"

To me this implies this is returned when the control is empty (not when there already is a perfecty valid date in it).

Bart Broersma

2016-08-02 19:43

developer   ~0093974

Feel free to provide a patch for the documentation in a separate issue.
Please close this one.

Dmitry D. Chernov

2017-02-02 09:10

reporter   ~0097905

I was forced to reopen this issue because it wasn't fixed properly in 1.6.2.
If TDateEdit.Text is empty, it will be set to the current date on the first reopening of the project. If form is then saved, new value will be saved too, even in LRT file. This forces programmer to clear TDateExit.Text value manually after every opening of the project.

Bart Broersma

2017-02-02 11:27

developer   ~0097915

This happens when (DefaultToday = True) and (DirectInput = False).
With DirectInput beig False the Text in the control MUST be valid at all times.
So this is to be expected.

Bart Broersma

2017-02-02 12:34

developer   ~0097921

Please test with trunk.
I've tried to make it so that toggling DirectInput will not alter empty Text in design mode.

Dmitry D. Chernov

2017-02-02 16:43

reporter   ~0097924

> This happens when (DefaultToday = True) and (DirectInput = False).

Yes, and this is exactly the case meant.

I will test with trunk a bit later, maybe some hours.

Dmitry D. Chernov

2017-02-02 19:37

reporter   ~0097930

lazarus-1.7-54062-20170202: bug is still present: Text reassigned to the current date after project reopening. DirectInput is False.

Bart Broersma

2017-02-02 19:54

developer   ~0097932

Last edited: 2017-02-02 19:55

View 2 revisions

I cannot reproduce that at all.
I tested all combinations of defaultToday and DirectInput, with an intial empty control (text = '').
Toggling does not alter the control's text.
Saving and re-openin does not alter the control's text.
In all cases the text remains empty.

Tested on Windows.

Did you actually rebuild the IDE?

Note: at runtime the control is filled with current date if DefaultToday = True and Text is empty, which is by design.

Bart Broersma

2017-02-02 20:12

developer   ~0097933

Just realized:
> lazarus-1.7-54062

You did notice that I fixed it in r54070, did you?

Dmitry D. Chernov

2017-02-03 09:13

reporter   ~0097940

lazarus-1.7-54077-20170203: everything seems to be working now, thanks.

Issue History

Date Modified Username Field Change
2016-07-30 11:48 Dmitry D. Chernov New Issue
2016-07-30 14:33 Bart Broersma Assigned To => Bart Broersma
2016-07-30 14:33 Bart Broersma Status new => assigned
2016-07-30 14:35 Bart Broersma LazTarget => -
2016-07-30 14:35 Bart Broersma Note Added: 0093904
2016-07-30 14:35 Bart Broersma Status assigned => feedback
2016-07-30 15:01 Bart Broersma File Added: editbtn.diff
2016-07-30 15:02 Bart Broersma Note Edited: 0093904 View Revisions
2016-07-30 17:59 Dmitry D. Chernov Note Added: 0093906
2016-07-30 17:59 Dmitry D. Chernov Status feedback => assigned
2016-07-30 18:01 Dmitry D. Chernov Note Edited: 0093906 View Revisions
2016-07-30 19:07 Bart Broersma Note Added: 0093908
2016-07-30 19:12 Bart Broersma Note Edited: 0093908 View Revisions
2016-07-30 19:13 Bart Broersma Note Edited: 0093908 View Revisions
2016-07-30 19:14 Bart Broersma Status assigned => feedback
2016-07-31 03:39 Dmitry D. Chernov Note Added: 0093910
2016-07-31 03:39 Dmitry D. Chernov Status feedback => assigned
2016-07-31 11:11 Bart Broersma Note Added: 0093911
2016-07-31 11:11 Bart Broersma Status assigned => feedback
2016-08-02 05:34 Dmitry D. Chernov Note Added: 0093956
2016-08-02 05:34 Dmitry D. Chernov Status feedback => assigned
2016-08-02 18:29 Bart Broersma Note Added: 0093967
2016-08-02 18:33 Bart Broersma Fixed in Revision => r52777
2016-08-02 18:33 Bart Broersma LazTarget - => 1.6.2
2016-08-02 18:33 Bart Broersma Note Added: 0093968
2016-08-02 18:33 Bart Broersma Status assigned => resolved
2016-08-02 18:33 Bart Broersma Fixed in Version => 1.6.2
2016-08-02 18:33 Bart Broersma Resolution open => fixed
2016-08-02 18:33 Bart Broersma Target Version => 1.6.2
2016-08-02 19:08 Dmitry D. Chernov Note Added: 0093972
2016-08-02 19:08 Dmitry D. Chernov Status resolved => assigned
2016-08-02 19:08 Dmitry D. Chernov Resolution fixed => reopened
2016-08-02 19:41 Bart Broersma Note Added: 0093973
2016-08-02 19:43 Bart Broersma Note Added: 0093974
2016-08-02 19:43 Bart Broersma Status assigned => resolved
2016-08-02 19:43 Bart Broersma Resolution reopened => fixed
2016-08-02 19:43 Bart Broersma Note Edited: 0093973 View Revisions
2016-08-03 07:56 Dmitry D. Chernov Status resolved => closed
2017-02-02 09:10 Dmitry D. Chernov Note Added: 0097905
2017-02-02 09:10 Dmitry D. Chernov Status closed => assigned
2017-02-02 09:10 Dmitry D. Chernov Resolution fixed => reopened
2017-02-02 11:27 Bart Broersma Note Added: 0097915
2017-02-02 12:34 Bart Broersma Fixed in Revision r52777 => r52777, r54070
2017-02-02 12:34 Bart Broersma Note Added: 0097921
2017-02-02 12:34 Bart Broersma Status assigned => resolved
2017-02-02 12:34 Bart Broersma Resolution reopened => fixed
2017-02-02 16:43 Dmitry D. Chernov Note Added: 0097924
2017-02-02 19:37 Dmitry D. Chernov Note Added: 0097930
2017-02-02 19:37 Dmitry D. Chernov Status resolved => assigned
2017-02-02 19:37 Dmitry D. Chernov Resolution fixed => reopened
2017-02-02 19:54 Bart Broersma Note Added: 0097932
2017-02-02 19:54 Bart Broersma Status assigned => feedback
2017-02-02 19:55 Bart Broersma Note Edited: 0097932 View Revisions
2017-02-02 20:12 Bart Broersma Note Added: 0097933
2017-02-02 20:12 Bart Broersma Status feedback => resolved
2017-02-02 20:12 Bart Broersma Resolution reopened => fixed
2017-02-03 09:13 Dmitry D. Chernov Note Added: 0097940
2017-02-03 09:13 Dmitry D. Chernov Status resolved => closed