Recent

Author Topic: [SOLVED] Assign NULL value to TDateTimePicker ...  (Read 16970 times)

patyi

  • Full Member
  • ***
  • Posts: 168
[SOLVED] Assign NULL value to TDateTimePicker ...
« on: January 13, 2015, 10:31:07 pm »
Hi !

How can assign NULL value to TDateTimePicker on runtime ? I want to initialize TDateTimePicker control with NULL date.
I set NullInputAllowed := True, TextForNullDate := '-' ...

Thanks.
« Last Edit: January 14, 2015, 09:59:27 am by patyi »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Assign NULL value to TDateTimePicker ...
« Reply #1 on: January 13, 2015, 11:55:52 pm »
Would
Code: [Select]
  picker.DateTime:=NullDate;
not do it?

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: Assign NULL value to TDateTimePicker ...
« Reply #2 on: January 14, 2015, 12:37:33 am »
In procedure TCustomDateTimePicker.Paint there is a condition
Code: [Select]
  if DateIsNull and (FTextForNullDate > '') 
                       and (not (FTextEnabled and Focused)) then begin

If you remove the second line ("and (not FTextEnabled and Focused))") then the NULL works correctly.

The "FTextEnabled" becomes false if the control is disabled or the property "Checked" is false (see method "GetChecked"). But, if I try to turn off "Checked" in the Object Inspector it immediately jumps back to the checked state.

I don't know what this "Checked" is good for, but I guess this is a bug. Please file a bug report, and the author will certainly fix the bug quickly. In the meantime, you probably can live with the patch mentioned above.

patyi

  • Full Member
  • ***
  • Posts: 168
Re: Assign NULL value to TDateTimePicker ...
« Reply #3 on: January 14, 2015, 09:58:33 am »
picker.DateTime:=NullDate; doing the job, thanks howardpc  :D

I just guess, checked property is for checking valid date !? May be Zoran can answer this question ...

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Assign NULL value to TDateTimePicker ...
« Reply #4 on: January 14, 2015, 12:13:37 pm »
picker.DateTime:=NullDate; doing the job, thanks howardpc  :D
I'm glad you solved the problem. :)

I just guess, checked property is for checking valid date !? May be Zoran can answer this question ...

No, checking if date is valid is always active. You just can't enter invalid date.
The Checked property has purpose only when ShowCheckBox is set to True, as documented in wiki page:
Quote
If ShowCheckBox is set to True, this property determines whether the check box is checked or not. If ShowCheckBox is False, this property has no purpose and is automatically set to True.

The purpose of these (ShowCheckBox and Checked) properties is Delphi compatibility (see http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.ComCtrls.TDateTimePicker.Checked and http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.ComCtrls.TDateTimePicker.ShowCheckbox).
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Assign NULL value to TDateTimePicker ...
« Reply #5 on: January 14, 2015, 12:43:49 pm »
If you remove the second line ("and (not FTextEnabled and Focused))") then the NULL works correctly.

wp, if you still think that NULL works incorretly (and that it can be solved by removing this second line), would you please provide a project which illustrates incorrect behaviour.

There is a reason for the second line, the purpose is the behaviour described under Displaying null values (near the bottom of the page):
Quote
When the control gets focus, the text changes to defined format, but displaying zeros for date parts and nines for time parts (for example "00/00/0000 99:99:99"), which is appropriate to user input.
« Last Edit: January 14, 2015, 12:50:36 pm by Zoran »
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

patyi

  • Full Member
  • ***
  • Posts: 168
Re: [SOLVED] Assign NULL value to TDateTimePicker ...
« Reply #6 on: January 14, 2015, 01:35:17 pm »
Hi, Zoran !
Thanks for explanation and for the great component !

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: [SOLVED] Assign NULL value to TDateTimePicker ...
« Reply #7 on: January 14, 2015, 04:51:45 pm »
Quote
wp, if you still think that NULL works incorretly (and that it can be solved by removing this second line),
would you please provide a project which illustrates incorrect behaviour.

See the attached project: I created a new project and added a TDateTimePicker, set the "TextForNullDate" to "-", and set the "Date" to NULL by pressing "n" in the Date property field. At designtime the DateTimePacker does show the "-". But when I compile there is a zero date display "00.00.0000" which I think is wrong - why should I select a NULL date if is is only used at design-time?

If a remove the second line mentioned above the dash ("-") appears also at runtime.

Tested with Laz trunk / fpc 2.6.4 / Win 7 (32 bit app, but 64 bit Win)
« Last Edit: January 14, 2015, 07:24:36 pm by wp »

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: [SOLVED] Assign NULL value to TDateTimePicker ...
« Reply #8 on: January 15, 2015, 02:13:33 pm »
Quote
wp, if you still think that NULL works incorretly (and that it can be solved by removing this second line),
would you please provide a project which illustrates incorrect behaviour.

See the attached project: I created a new project and added a TDateTimePicker, set the "TextForNullDate" to "-", and set the "Date" to NULL by pressing "n" in the Date property field. At designtime the DateTimePacker does show the "-". But when I compile there is a zero date display "00.00.0000" which I think is wrong - why should I select a NULL date if is is only used at design-time?

If a remove the second line mentioned above the dash ("-") appears also at runtime.

Tested with Laz trunk / fpc 2.6.4 / Win 7 (32 bit app, but 64 bit Win)

But... of course it is intended behaviour. If you put another control on the form (put a Button), then in runtime when focus is not on DateTimePicker, you will see the "-". If you remove this "second line", then, how will the user edit the control? Don't you think that this feature (when the control with NULL value receives focus, the display changes to editable format, but with zeros) is very useful?
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: [SOLVED] Assign NULL value to TDateTimePicker ...
« Reply #9 on: January 15, 2015, 03:07:23 pm »
I had never used the control before and had only one control in the form - yes, you are right.

 

TinyPortal © 2005-2018