TAdvDateTimePicker

Hi, I have a problem with TAdvDateTimePicker. My application uses simple method to ensure, that when an user doesn't want to fill a date, the field remains blank. That method is - set format to ' ' (space) and when needed, the format is reverted back to '' (empty string).


After update to newest version of TMS component pack, the behavior has changed - after setting format back to an empty string, the format is effective only until change of focus.

It can be simulated by a form with two buttons and one datetime picker, set to Kind:= dkDate in design time and following code:



procedure TForm2.FormActivate(Sender: TObject);
begin
  AdvDateTimePicker1.Format:= ' ';
end;


procedure TForm2.Button1Click(Sender: TObject);
begin
  AdvDateTimePicker1.Format:= '';
end;


procedure TForm2.Button2Click(Sender: TObject);
begin
  AdvDateTimePicker1.Format:= ' ';
end;


First button should revert the format to original state. It does do it, but only until, for example, user clicks on the picker. Then the format is reverted back to previous (a space) and correctly displayed date dissapears.
Is it desired behavior? Can I achieve what I need another way, perhaps using the new NullDate* properties? If so, could you please tell me how? Thank you

The second button behaves correctly - after setting the format to a space, the field remains blank all the time

you could use NullDate to achive a blank field in case of a "null date" ... just try and set NullDateDate property to the desired date.

Yes, we introduced NullDateFormat & NullDateDate to achieve this directly.

Example:
begin
  advdatetimepicker1.NullDateFormat := ' ';
  advdatetimepicker1.DateTime := 0;
end;

shows an empty value.
Also, pressing Ctrl-Del in the date editor, will clear the date part when  advdatetimepicker.NullDateFormat = ' ';

Thank you for reply. It partially works... But it seems, that

1. both the date and datetime properties must be set to some date (without time in the datetime property) in design time for the null date format to work at all. If there is a time present in the datetime property, then the null format is not applied even if the date is equal to the null date. OK I can live with that
2. the change from null to not null date still doesn't work, if I do the change in onEnter action

here is my code: (still one form with two buttons, one AdvDateTimePicker set to dpDate, NullDateDate:= 1.1.1900 and NullDateFormat:= ' '; plus one TEdit. )



procedure TForm2.FormActivate(Sender: TObject);
begin
  AdvDateTimePicker1.date:= AdvDateTimePicker1.NullDateDate;
end;


procedure TForm2.AdvDateTimePicker1Enter(Sender: TObject);
begin
  AdvDateTimePicker1.date:= now;
end;


procedure TForm2.Button1Click(Sender: TObject);
begin
  AdvDateTimePicker1.date:= now;
end;


procedure TForm2.Button2Click(Sender: TObject);
begin
  AdvDateTimePicker1.date:= AdvDateTimePicker1.NullDateDate;
end;


first button "reveals" the date, that is OK. Second button "hides it", that is OK. On enter to the picker, date is displayed correctly, but clicking into the TEdit "hides" it again. It looks like the onEnter action is being ignored, as the behavior is same if I don't use it at all. How could I do it? It was very simple thing before the component has been changed...

3. I don't seem to be able to combine MinDate property with these NullDate* properties, without silly workarounds. If I use NullDateDate:= 1.1.1900 and MinDate:= 1.1.1999, then I am not able to set NullDateDate without altering the MinDate before...

@Bruno Fierens - thank you, your reply made me understand, that I can use 0 in the Date and DateTime properties, but doing that unfortunatelly it does not change the behavior described above...

What does your code do when you enter the TEdit?


Using NullDateDate should remove the need for manually setting the format to ' ' (blank) or change the date.

@Rasmussen Bjarne: Nothing happens in my code at all... I figured out, that it should remove the need to set the format back, but even if I remove the onEnter action, the behavior is still the same.

I need a simple thing - a datetimepicker, that can be set to blank when a form loads. Then, when entered, today's date should appear and stay there (and visible), no matter where on the form is the focus. Now I am not able to do it my old way, neither the new way...

We have seen an issue with setting the Date programmatically from the OnEnter event and applied a fix for this. With this fix, initializing the component with:


  AdvDateTimePicker1.NullDateFormat := ' ';
  AdvDateTimePicker1.DateTime := 0;

and have the event handler for OnEnter:

procedure TForm5.AdvDateTimePicker1Enter(Sender: TObject);
begin
  if AdvDateTimePicker1.NullDateFormat = ' ' then
  begin
    AdvDateTimePicker1.NullDateFormat := '';
    AdvDateTimePicker1.DateTime := Now;
  end;
end;

behaves as you specify. For an incremental source update with this fix, please contact us by email.
Easiest fix must be :

Use OnExit  - not OnEnter.


procedure TForm1.AdvDateTimePicker1Exit(Sender: TObject);
begin
  if AdvDateTimePicker1.DateTime = AdvDateTimePicker1.NullDateDate then
    AdvDateTimePicker1.DateTime := now;
end;


But the problem still happens - when a user wants to disable the NullDate functionality while having it activated (focus is on a TAdvDateTimePicker).
One way to correct this can be achieved by adding a "setter" for the NullDateFormat property.

procedure TAdvDateTimePicker.SetNullDateFormat(const Value: String);
begin
  FNullDateFormat := Value;
  FInternalChangedFlag := false; // reset when changing NullDateFormat
end;


With this - the user can disable the NullDate handling on the OnEnter event (not the OnExit though!) ....

This can only be done by changing the source for TAdvDateTimePicker ... since the FInternalChangedFlag must be kept private.


We have applied a fix and with this fix OnEnter can be used.

Sounds great Bruno!


But did we help Janacek Michael? Is the problem solved now?

As I explained, with the fix applied, the desired behavior of Michael should be possible. So, I invite Michael to contact us by email to get & apply this fix and test it in his application.