Solved

spinner for Ttime data type?

Posted on 2002-07-02
6
230 Views
Last Modified: 2010-04-04
Hi,

Is there any spinner control for ttime data type?

it must be in the format of hh:nn (24 hours), no AM/PM

thanks.
0
Comment
Question by:llkhor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7125455
I couldnt find a pre-made component to do this but you could do something like below:

Stick a TEdit and a TUpDown on a form and then use the below code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Can all be set in Object Inspector if you wanted to.
  Edit1.ReadOnly := True;
  UpDown1.Max := 32767;  // Max value of UpDown.Max property
  UpDown1.Min := -32768; // Min value of UpDown.Max property
end;

procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
var
  Hours, Minutes : ShortInt;
  Temp : string;
begin
  Hours := StrToInt(Copy(Edit1.Text, 1, 2));
  Minutes := StrToInt(Copy(Edit1.Text, 4, 2));
  if Button = btNext then
    Inc(Minutes)
  else
    Dec(Minutes);
  if Minutes > 59 then
  begin
    Minutes := 0;
    Inc(Hours);
  end;
  if Minutes < 0 then
  begin
    Minutes := 59;
    Dec(Hours);
  end;
  if (Hours > 23) and
     (Minutes > 0) then
  begin
    Hours := 0;
    Minutes := 0;
  end;
  if Hours < 0 then
  begin
    Hours := 24;
    Minutes := 0;
  end;
  if Length(IntToStr(Hours)) = 1 then
    Temp := '0' + IntToStr(Hours) + ':'
  else
    Temp := IntToStr(Hours) + ':';
  if Length(InttoStr(Minutes)) = 1 then
    Temp := Temp + '0' + IntToStr(Minutes)
  else
    Temp := Temp + IntToStr(Minutes);
  Edit1.Text := Temp;
end;

If you wanted it so users can enter data in as well, then you could use the same code along with a maskedit instead of a editbox.

Cheers,

Alan
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7126536
does not have the datetimepicker a spinner,
if datekind is set to dktime?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7126658
just for setting the format you want use

datetimepicker1.perform(DTM_SETFORMAT, 0, longint(pchar('YourTimeFormatString')));

sample
datetimepicker1.perform(DTM_SETFORMAT, 0, longint(pchar('hh:nn')));

not tested, but should work

meikl ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:llkhor
ID: 7142220
thanks for your reply.


alanwincup,

I'm actually looking for a ready made component or the standard components, with little or no coding needed. Anyhow, thanks for your code, it works.


kretzschmar,
I get undefined variable DTM_SETFORMAT when i tried out the code. I think datetimepicker's spin function supports only 12 hour format, but what i need is 24 hours format.

quenstion is, could I set datetimepicker to 24 hours format?

Thanks.






0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 7142547
0
 

Author Comment

by:llkhor
ID: 7155971
thanks kreztschmar,

it works.  but need to change the format string to 'HH:MM' for the 24 hours format.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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