Solved

spinner for Ttime data type?

Posted on 2002-07-02
6
224 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now