Solved

Integer into timer?

Posted on 1998-08-30
6
234 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
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: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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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