Solved

spinner for Ttime data type?

Posted on 2002-07-02
6
231 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
Independent Software Vendors: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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