Recent

Author Topic: DateTimePicker: A Comment & Suggestion  (Read 2263 times)

mtrsoft

  • New Member
  • *
  • Posts: 44
DateTimePicker: A Comment & Suggestion
« on: November 18, 2018, 11:20:17 pm »
I'm using Lazarus 1.8.4 on a Win7/32 system.

COMMENT:

Most Comboboxes will display the dropdown list when the Alt+Down key combination is pressed.

This key combination does not work with the DateTimePicker. -- OR am I missing somethting?)

Creating a DateTimePicker descendant that overrides the KeyDown method does not work because the descendant needs to call the method/procedure DropDownCalendarForm and this method is not visible to the descendant.

THE SUGGESTION:

In the TDateTimePicker class (which is located in the datetimepicker.pas file) move the DropDownCalendarForm procedure from the "Private" section to the "Protected" section or the "Public" section.

Doing this will make it possible to create a descendant that implements the Alt+Down functionality.

A partial example of such a descendant is given in the following code:

Code: Pascal  [Select][+][-]
  1. unit mtrsDTPicker;
  2.  
  3. { NOTE:
  4.   This unit depends on the procedure "DropDownCalendarForm" in DateTimePicker.pas
  5.   being moved from the "Private" to the "Protected" section of the source code
  6.   in the TCustomDateTimePicker class.
  7.   This change in "visiblity" is required so that this descendant can call the
  8.   DropDownCalendarForm procedure.
  9. }
  10.  
  11. {$mode objfpc}{$H+}
  12.  
  13. interface
  14.  
  15. uses
  16.   Classes
  17.   //, SysUtils
  18.   , DateTimePicker
  19.   ;
  20.  
  21. Type
  22.   TmtrDTPicker = Class(TDateTimePicker)
  23.   protected
  24.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  25.   end;
  26.  
  27. implementation
  28.  
  29. Uses
  30.   Windows  {This is required so that the VK_DOWN constant is recognized.}
  31.   ;
  32.  
  33. procedure TmtrDTPicker.KeyDown(var Key: Word; Shift: TShiftState);
  34. begin
  35. If (Key = VK_DOWN) and (Shift = [ssAlt]) then
  36.   begin
  37.   Key := 0;
  38.   Shift := [];
  39.   If NOT DroppedDown then DropDownCalendarForm;
  40.   exit;
  41.   end;
  42.  
  43. Inherited;
  44. end;
  45.  
  46. end.
  47.  

I have not checked the TdbDateTimePicker class, but assume that the above suggested change will automatically propigate to it.

Regards,
John

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: DateTimePicker: A Comment & Suggestion
« Reply #1 on: November 19, 2018, 12:32:13 am »
Makes sense. In Laz trunk the method is protected now.

BTW: You should use "LCLType" (and in other cases also "LCLIntf", "LMessages", "LCLProc", instead of "Windows" and "Messages") so that your derived component is still cross-platform.
« Last Edit: November 19, 2018, 12:47:24 am by wp »

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: DateTimePicker: A Comment & Suggestion
« Reply #2 on: December 20, 2018, 09:42:10 am »
Sorry, I didn't notice this topic earlier.
The described behaviour of Alt+Down key combination is now built in TDateTimePicker (in trunk).
Also, Alt+Up now closes the calendar and returns focus to main control (also follows combo box behaviour).

Thank you for noticing this.

 

TinyPortal © 2005-2018