1

I am working on a timesheet application where the user will enter the work time of the staffs for morning, afternoon and evening (overtime).

As we all know this is a very tedious job for the user, I trying to find a way to make it easier to the user, particularly the use the period (.) instead of a colon (:) for the time entries.

Say for example: The user enters 8.15 in the DBGrid column titled "AM Time-In". The computer upon pressing "enter" automatically converts to 8:15 AM.

Hence, 1. Is there a way that I can do this in my Delphi 10.3 Rio? 2. I also wanted to change the 24 hour format to 12 hour?

I will appreciate any help for this. Thank you.

Mel
  • 101
  • 1
  • 9
  • Try the before post event of the dataset you are using and how to format dbgrid cells – Nasreddine Galfout Sep 25 '19 at 12:53
  • 1
    Why don't you set up an [EditMask](http://docwiki.embarcadero.com/Libraries/Tokyo/en/Data.DB.TField.EditMask) for certain Field/DBGrid column? By using `EditMask` you can achieve so that users won't even have to enter period or colon character at all. – SilverWarior Sep 25 '19 at 15:21
  • @SilverWarior It works like charm! The way I want it. Thank you so much! – Mel Sep 25 '19 at 22:32
  • @NasreddineGalfout Thank you for your suggestion but the latter seems work for me. – Mel Sep 25 '19 at 22:35
  • I want the solution of SilverWarior to be flagged or voted as answered but I do not know how to do it here? – Mel Sep 25 '19 at 22:36
  • @Mel I first have to write my solution as an aswer an not just as a coment like I have done this now. So feel free to mark my answer bellow as solution to your question now. – SilverWarior Sep 26 '19 at 06:25

1 Answers1

2

You should set up an EditMask for specific Field/DBGrid column. This Will allow you to use the EditMaks itself for automatically entering needed period or colon characters so your users won't have to write them yourself.

EditMasks are most commonly used for fields that accept date and time information.
But they can be used basically for any data entry that has fixed format like for instance IBAN numbers, telephone numbers, carplates numbers, IP address numbers and so on.

PS: If you are developing your application to be used around the world don't forget that different countries my used different formats for expressing time and dates. This means that you will have to set the appropriate EditMask value at runtime.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • Thanks for this very profound solution. Greatly appreciate it! However, I still have one more question, I forgot to follow through. How can I change the 24 hour to 12 hour format. Like you said, I should be careful with different formats. – Mel Sep 26 '19 at 08:26