Solved

Integer into timer?

Posted on 1998-08-30
6
233 Views
Last Modified: 2010-04-04
What is the best/easiest way to convert an integer to a timer format 00:00:00? The integer is increased every second. All I need is a simple timer that I can display in a label.

Thanks
0
Comment
Question by:LostOne
[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
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1338168
How about this???

Have a timer and set the Interval to 1000 milisecs..then enter this code in the OnTimer()

Label1.Caption := TimeToStr(Time);

Is this what you need?? I mean is it the time or date that you want to show??
0
 

Author Comment

by:LostOne
ID: 1338169
I want to show a timer that starts at 00:00:01 and increases every second.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1338170
How about this..???
Set the timers interval to 1000 then enter this code...
var
  I : integer;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(i);
  if i > 9 then
    Label1.Caption := '00:00:' + IntToStr(i)
  else
    Label1.Caption := '00:00:0' + IntToStr(i);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  I := 0;
end;

Regards,
Viktor Ivanov
0
Technology Partners: 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:LostOne
ID: 1338171
that would work from 0 to 60 seconds but not after that.
59 sec would be 00:00:59
1 min would be 00:01:00
1 hour would be 01:00:00

the format i'm looking for is [hour]:[min]:[sec]
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338172
Wait ....this one is better without using integers, but real DateTime type..

var
  StartTime : TDateTime;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := FormatDateTime('hh:nn:ss', Time - StartTime);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StartTime := Time;
end;

Hope this is what you're looking for ;-)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338173
Actually you can do it with integers the way you wanted, but you need to play a little with the if then conditions....
var
  h, m, s : Byte;
begin
  Inc(s);
     if s > 9 then
       Label1.Caption := '00:00:' + IntToStr(s)
     else if s > 60 then
     begin
       Inc(m);
       if m > 9 then
         Label1.Caption := '00:'+IntToStr(m) +':'+IntToStr(i)
       else
        Label1.Caption := '00:0'+IntToStr(m) +':'+IntToStr(i);
end
  else
       Label1.Caption := '00:00:0' + IntToStr(s);
end;

and so on...you got the idea...

Regards,
Viktor Ivanov
0

Featured Post

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!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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