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
Solved

spinner for Ttime data type?

Posted on 2002-07-02
6
229 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 81
How to renew a Delphi rad-studio licence? 5 69
Controlled Assessment GCSE - desperate help needed 4 102
DBGrid or StringGrid ? 6 104
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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