Recent

Author Topic: TTimeEdit time format hh:mm:ss and hh:mm  (Read 3049 times)

Vodnik

  • Full Member
  • ***
  • Posts: 210
TTimeEdit time format hh:mm:ss and hh:mm
« on: January 22, 2019, 03:30:35 pm »
I used TDateTimePicker with success, but users prefer separate fields for date and time :(
TTimeEdit shows time as HH:MM. I have several time fields, in some I have to show time as HH:MM, in others - as HH:MM:SS (duration). Is it possible to do this with TTimeEdit?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TTimeEdit time format hh:mm:ss and hh:mm
« Reply #1 on: January 22, 2019, 04:00:51 pm »
I can see no simple way to get what you want, since SetTime - the method which controls the time display - is private (not protected) and is not declared as virtual. In other words the control has not been designed to be readily subclassed to extend its functionality.

However, it would be straightforward to write a replacement that offered either long or short time format as a property which defaulted, say, to the short format.
The attached project shows one way to adapt the LCL component. It is just a copy and paste from the sources with a few alterations.

I hope someone may be able to show us a better way to adapt the LCL component than by duplicating 95% of the existing code, but I don't myself know how else to do it.
« Last Edit: January 22, 2019, 05:19:41 pm by howardpc »

Vodnik

  • Full Member
  • ***
  • Posts: 210
Re: TTimeEdit time format hh:mm:ss and hh:mm
« Reply #2 on: January 22, 2019, 09:21:24 pm »
Thank you, howardpc!
I didn't expect that a new component is needed for this.
Specific application may also require to show/edit time intervals including milliseconds, then more adaptation should be done.
Your project works fine, of course, but in my 1.8.4 I had to comment out:
//    property Images;
//    property ImageIndex;
//    property ImageWidth;
Going beyond the true path, I thought about:
- come back to TDateTimePicker: one for Date, one for Time, one for Duration
- using TMaskEdit

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TTimeEdit time format hh:mm:ss and hh:mm
« Reply #3 on: January 25, 2019, 03:04:24 pm »
Thank you, howardpc!
I didn't expect that a new component is needed for this.
Specific application may also require to show/edit time intervals including milliseconds, then more adaptation should be done.
Your project works fine, of course, but in my 1.8.4 I had to comment out:
//    property Images;
//    property ImageIndex;
//    property ImageWidth;
Going beyond the true path, I thought about:
- come back to TDateTimePicker: one for Date, one for Time, one for Duration
- using TMaskEdit

Simply use two DateTimePickers.
In the first set Kind property to dtkDate.
In the other set Kind to dtkTime and use TimeDisplay property to adjust which time parts should be shown.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TTimeEdit time format hh:mm:ss and hh:mm
« Reply #4 on: January 25, 2019, 03:24:20 pm »
The TTimeEdit was not designed for hh:mm:ss format.
It is a simple control to just pick a time (which is rather obvious from it's default behaviour).
A TDateTimePicker would be more suitable for your needs.

Bart

 

TinyPortal © 2005-2018