looking for Time Picker

Posted on 2004-09-17
Last Modified: 2010-05-18

I am looking for a Time Picker Control (not datetime) where I can specify the minimum and maximum times that can be selected.

Any ideas?

Question by:Voodooman
LVL 17

Assisted Solution

mokule earned 25 total points
ID: 12088329

What about TDateTimePicker set Kind to dtkTime and use OnChange event.
LVL 22

Accepted Solution

Ferruccio Accalai earned 25 total points
ID: 12088513
yeah mokule, was suggesting the same :) an example:

procedure TForm1.FormCreate(Sender: TObject);
datetimepicker1.Kind :=  dtkTime;
datetimepicker1.DateTime := strtotime('10.00.00');

procedure TForm1.DateTimePicker1Change(Sender: TObject);
if (datetimepicker1.Time > strtoTime('22.00.00')) or
   (datetimepicker1.Time < strtotime('10.00.00')) then begin
      Showmessage('Time must be between 10.00.00 and 22.00.00');
      datetimepicker1.Time := strtotime('10.00.00');

F68 ;-)

Author Comment

ID: 12088842

Sorry guys its not what I'm looking to do.

I could do this when I validate the data on the form.

When I load the popup, I want to prevent the users from selecting outside the limits of the day (that I set).

I don't want to work around it - this is a very nice high end piece of softare - hence I need to deal with the problem - not work around it!


ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 12088969
--> When I load the popup
I first place you just said '...where I can specify the minimum and maximum times that can be selected...'

Maybe if you give more info about your needs we can suggest something more than a 'workaround', but for what is knowed until now mokule suggestion is an answer, not just a workaround....

What do you mean with 'when i load the popup'? what is the situation?

F68 ;-)
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12090841

Do you mean you want to prevent the user to choose date out of the range you woud like to set?

if so then use MinDate and MaxDate to set the range for the TDateTimePicker

  DateUtils ;

procedure TForm1.FormCreate(Sender: TObject);
  DateTimePicker1.MinDate := IncDay(Date,-5);
  DateTimePicker1.MaxDate := Date;

Author Comment

ID: 12091102

Firstly - apologies if anyone thought I was being unappreciative of the answers - this is not the case.  I try to help with answers, and I have been on EE for 5 years - mostly in the VB area - where I have answered hundreds of questions and hopefully helped some people.

F68 - I was quite clear in what I asked for - its a time picker where I can select the maximum and minimum times that a user can select.

The popup is a modal form where the user edits appointments.  The appointments must only be possible within the working day.

When I save the record I can easily tell the user that the time the user has selected is outside of the day.

If I wanted to do that I would do it.  The professional approach is to prevent the user making the mistake in the first place.

I would like a control like Lotus Organiser (if you havent seen it you wouldnt know what I mean) - lathough any control that limited the day (e.g. 08:00 - 17:00) would do.

Lotus use a drop down slider to adjust the time - it is fast and efficient and is limited to the extent of the day setup.

I was hoping that one of the experts may have seen such a control - bearing in mind the large number of excellent controls that there are for Delphi - surely one of the main reasons for using Delphi.

LVL 12

Expert Comment

ID: 12091110
1) As Mocule said, adjust it to Kind of dtkTime and you will be able to change only time. Then using methods ReplaceDate and ReplaceTime you can make the DateTime you need.


Author Comment

ID: 12091280

I have found a control that works for me - TADVSpinEdit from  Luckily I have bought this already as part of a package (I think it is also on the Delphi7 Companion CD).

This spin edits the time.

With this, the user cannot type into the box - they can only increment the time up and down with the spin button.

This has the advantage that the user can see when they have reached the top or bottom of the limit - without having to be told with a message box.

Using a simple bit of code under the change event the time spins only with the limits.

if strtotime(spintime.Text)<strtotime('10:00') then

     if strtotime(spintime.Text)>strtotime('17:00') then

By doing this I can make sure that users cannot set appointments out of the day without nagging them.  It also allows different ranges to be used on different days (e.g. Half Day on Saturday).

I will split the points between Mokule and F68 - thanks for the idea, and thanks all for the help!


Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 143
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
PHP preg_replace code convert to Delphi 14 56
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question