Recent

Author Topic: [SOLVED] TDateTimePicker problem  (Read 3575 times)

dseligo

  • Hero Member
  • *****
  • Posts: 578
[SOLVED] TDateTimePicker problem
« on: December 28, 2021, 09:45:58 am »
When I set Date property to 'null' in Object inspector (either by pressing 'N' in Datetimepicker editor or by simply entering 'null') I get error 'Error reading DateTimePicker1.Date: Floating point overflow' when form is created in program.

If I set date property to 'null' programatically with DateTimePicker1.Date := NullDate; then it works.

Reproduction: put DateTimePicker on form, set Date property to 'null', run the program.

I have Lazarus 2.0.10, FPC 3.2.0, Windows 11.
Target OS is Win32, target CPU family is 386.
« Last Edit: December 29, 2021, 12:31:39 pm by dseligo »

winni

  • Hero Member
  • *****
  • Posts: 3045
Re: TDateTimePicker problem
« Reply #1 on: December 28, 2021, 09:59:28 am »
Hi!

No problems here.

Laz 2.0.12 fpc 3.2 Linux64

Winni

dseligo

  • Hero Member
  • *****
  • Posts: 578
Re: TDateTimePicker problem
« Reply #2 on: December 28, 2021, 10:00:48 am »
When I compile it for target Win64, target CPU family x86_64 results are different, there is no error, but it also doesn't work as supposed to.

If Date property is set to 'null' in Object inspector then value shown in DateTimePicker is '30.12.1899'.
If Date property is set programatically with DateTimePicker1.Date := NullDate; then value shown is 'NULL' (so, it works).

Property TextForNullDate is 'NULL' (default value).

AlexTP

  • Hero Member
  • *****
  • Posts: 1766
    • UVviewsoft
Re: TDateTimePicker problem
« Reply #3 on: December 28, 2021, 10:12:09 am »
You cannot set the property Date to 'NULL' or another string - its type is TDate in the code.
Type of Time propety is TTime.

(Maybe Obj Inspector supports this as a feature?)
« Last Edit: December 28, 2021, 10:15:11 am by Alextp »

dseligo

  • Hero Member
  • *****
  • Posts: 578
Re: TDateTimePicker problem
« Reply #4 on: December 28, 2021, 10:22:44 am »
You cannot set the property Date to 'NULL' or another string - its type is TDate in the code.
Type of Time propety is TTime.

(Maybe Obj Inspector supports this as a feature?)

Yes, you can: https://wiki.freepascal.org/DateTimeCtrls_Package#NullInputAllowed:_Boolean

winni

  • Hero Member
  • *****
  • Posts: 3045
Re: TDateTimePicker problem
« Reply #5 on: December 28, 2021, 10:27:49 am »
You cannot set the property Date to 'NULL' or another string - its type is TDate in the code.
Type of Time propety is TTime.

(Maybe Obj Inspector supports this as a feature?)

Hi

That is wrong.

Nulldate is defined by the TDateTimePicker and you can enter "N" in the dialog for the date.

From the TDateTimePicker:

Code: Pascal  [Select][+][-]
  1. const
  2.   { We will deal with the NullDate value the special way. It will be especially
  3.     useful for dealing with null values from database. }
  4.   NullDate = TDateTime(Math.MaxDouble);  
  5.  

Winni

dseligo

  • Hero Member
  • *****
  • Posts: 578
Re: TDateTimePicker problem
« Reply #6 on: December 29, 2021, 04:24:10 am »
Update:
I tried Lazarus 2.0.10 on another computer with Windows 10 and it has a same problem.
Tried 2.0.12 on Windows 11, same problem.
With 2.0.8, FPC 3.0.4 on Windows 10 is fine (no problem).
With trunk 2.3.0 it's fine and with Lazarus 2.2.0 RC2, FPC 3.2.2 too.

I think I'll just use code to set 'null' in OnCreate event for now (until 2.2.0 will be released).

Zoran

  • Hero Member
  • *****
  • Posts: 1726
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker problem
« Reply #7 on: December 29, 2021, 11:25:08 am »
Yes, I experienced this couple of months ago.

This problem appears sometimes when loading this value from stream and only after Math.MaxDouble declaration was changed (fpc 3.2).

In FPC 3.0.4 (unit math) it was declared as:
  MaxDouble    =  1.7e+308;
In FPC 3.2 it is:
  MaxDouble    =  1.7976931348623157e+308;

After that, I changed the declaration of NullDate.
In Lazarus trunk it is no more declared as Math.MaxDouble, but explicitely:

  NullDate = TDateTime(1.7e+308);

With this change, the problem disappeared.
So, update Lazarus to trunk or, as a workaround, change the NullDate declaration yourself (datetimepicker.pas, line 55).

Zoran

  • Hero Member
  • *****
  • Posts: 1726
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker problem
« Reply #8 on: December 29, 2021, 12:22:23 pm »
Time flies, it was actually changed in may 2020. :o

See:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/6e4dbe9fd0e751052819a95de8bdc68b0474a53f

The comment says:
Quote
DateTimePicker: change declaration of NullDate - Math.MaxDouble declaration changed in fpc 3.2, and in some corner cases can make problems (mantis #37087). So, we'll just keep using 1.7e+308 (which was Math.MaxDouble in fpc 3.0.4).

dseligo

  • Hero Member
  • *****
  • Posts: 578
Re: TDateTimePicker problem
« Reply #9 on: December 29, 2021, 12:31:18 pm »
Yes, I experienced this couple of months ago.

This problem appears sometimes when loading this value from stream and only after Math.MaxDouble declaration was changed (fpc 3.2).

In FPC 3.0.4 (unit math) it was declared as:
  MaxDouble    =  1.7e+308;
In FPC 3.2 it is:
  MaxDouble    =  1.7976931348623157e+308;

After that, I changed the declaration of NullDate.
In Lazarus trunk it is no more declared as Math.MaxDouble, but explicitely:

  NullDate = TDateTime(1.7e+308);

With this change, the problem disappeared.
So, update Lazarus to trunk or, as a workaround, change the NullDate declaration yourself (datetimepicker.pas, line 55).

Thank you for explanation.

Zoran

  • Hero Member
  • *****
  • Posts: 1726
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker problem
« Reply #10 on: December 29, 2021, 12:42:05 pm »
Thank you for explanation.

You are welcome.

This change is included in Lazarus 2.2, which is about to be released.
So, you do not need trunk actually, you can take Lazarus 2.2 rc3.

Zoran

  • Hero Member
  • *****
  • Posts: 1726
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker problem
« Reply #11 on: December 29, 2021, 01:00:06 pm »
You cannot set the property Date to 'NULL' or another string - its type is TDate in the code.
Type of Time propety is TTime.

(Maybe Obj Inspector supports this as a feature?)

Object inspector supports it because there is a special property editor for it -- you can search for TDateTimePickerDateTimePropEditor class in unit DateTimePickerPropEdit, which is in DateTimeCtrlsDesign package.

 

TinyPortal © 2005-2018