Recent

Author Topic: TDateTimePicker focus problem  (Read 6528 times)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
TDateTimePicker focus problem
« on: February 03, 2017, 10:11:16 am »
Hi all,

The TDateTimePicker has an annoying behaviour regarding the focus: if you use a date format like dd.mm.yyyy, and leave the control while either the mm or yyyy part is focused, and you [tab] back to the TDateTimePicker control, the focus will return to where the control was left last. Instead, it should always focus the leftmost input field (dd in my example).

This seems to be the same in Delphi, there is a clumsy workaround described for Delphi (change the DateFormat to dfLong and back to dfShort), see http://stackoverflow.com/questions/23628192/returning-focus-to-first-part-of-delphi-tdatetimepicker-control, but this cannot be done in Lazarus, there is no DateTime Member in Lazarus's TDateTimePicker.

I tried variations of this trick with various other members of TDateTimePicker, but none reset the focus to the leftmost field.

How can I move the focus to the leftmost field?

Thx

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

balazsszekely

  • Guest
Re: TDateTimePicker focus problem
« Reply #1 on: February 03, 2017, 10:35:19 am »
To be honest I find the current behaviour logical, but it's ok if you prefer something else. Please try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DateTimePicker1Enter(Sender: TObject);
  2. begin
  3.   DateTimePicker1.SelectTime;
  4. end;

Zoran

  • Hero Member
  • *****
  • Posts: 1949
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker focus problem
« Reply #2 on: February 03, 2017, 01:33:56 pm »
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Re: TDateTimePicker focus problem
« Reply #3 on: February 03, 2017, 06:26:15 pm »
@Zoran: saw your reply in the other thread first, implemented it, worked.

@GetMem: this looks even shorter than Zoran's approach, tested and found working as well as Zoran's.

Since GetMem's approach it is shorter, I 'll go with GetMem's solution, fould no disadvantages so far.

Thanks very much guys,

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Re: TDateTimePicker focus problem
« Reply #4 on: February 22, 2017, 12:33:25 pm »
Hi Zoran,

I need your advice again. I tried to modify my application so that the DateTime Picker displays a placeholder, unless a valid date and time is entered.

I created a small demo project, and everything worked fine.

Then I tried to bring the changes over into my productive project. The DateTime picker is initialized like this in FormCreate:

Code: Pascal  [Select][+][-]
  1.   DateTimePickerBirthday.NullInputAllowed := True;
  2.   DateTimePickerBirthday.TextForNullDate := 'tt.mm.jjjj';
  3.   DateTimePickerBirthday.DateTime := NULLDATE;
  4.  

Nevertheless the DateTimePicker displays "30.12.1894", which seems to be the equivalent of DateTime := 0.

Using the debugger (oh my, I love open source ...) I tracked the problem to the third line of my code.

According to the debugger and my best confidence (I have never redefined NULLDATE), when that call is made, the Value of NULLDATE is 1,699999e+308. If I press F7 to step into your DateTimePicker source, my call arrives at

Code: Pascal  [Select][+][-]
  1. procedure TCustomDateTimePicker.SetDateTime(const AValue: TDateTime);
  2.  

and according to the debugger the Value of AValue has changed to 0. Your IsNullDate function returns "false", and the TextForNullDate is never displayed, but "30.12.1894".

Any idea why the value of AValue changes miraculously, and what I can do about it?

Thx

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Zoran

  • Hero Member
  • *****
  • Posts: 1949
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker focus problem
« Reply #5 on: February 22, 2017, 04:47:11 pm »
I can't reproduce it. Can you upload a simple application where problem appears?
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Zoran

  • Hero Member
  • *****
  • Posts: 1949
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDateTimePicker focus problem
« Reply #6 on: February 22, 2017, 04:51:07 pm »
Ah, unit EditBtn contains the constant of the same name, see: http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/nulldate.html

You probably have EditBtn also in uses section, do you?

So, replace
Code: Pascal  [Select][+][-]
  1. DateTimePickerBirthday.DateTime := NULLDATE;
with
Code: Pascal  [Select][+][-]
  1. DateTimePickerBirthday.DateTime := DateTimePicker.NullDate;
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

ArminLinder

  • Sr. Member
  • ****
  • Posts: 316
  • Keep it simple.
Re: TDateTimePicker focus problem
« Reply #7 on: February 22, 2017, 05:47:19 pm »
Yep, I have EditBtn in my uses section, as soon as I am home I'll give your solution a try, but it looks plausible.

What I wonder is, why the debugger did fail on me? The EditBtn constant is defined as 0 ... why did the debugger when stepping my code display the 1,699999€+308 value, which, in this context, is obviously not the value passed to the function !?

Armin.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

 

TinyPortal © 2005-2018