?
Solved

Integer into timer?

Posted on 1998-08-30
6
Medium Priority
?
236 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 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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