Solved

Integer into timer?

Posted on 1998-08-30
6
229 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:LostOne
Comment Utility
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
Comment Utility
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
Comment Utility
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

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

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

10 Experts available now in Live!

Get 1:1 Help Now