Solved

Integer into timer?

Posted on 1998-08-30
6
232 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
  • 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
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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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