?
Solved

Simple HH:MM:SS counter

Posted on 2003-11-14
6
Medium Priority
?
358 Views
Last Modified: 2010-04-05
How can I write a simple HH:MM:SS counter to time a procedures duration ?. The counter does not have to be very accurate just a start/stop counter to the nearest second or so. I would like a coded answer without using any components.

Thanks
Paul.
0
Comment
Question by:pr_wainwright
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 2

Expert Comment

by:DeNavigator
ID: 9749186
procedure ProcedureName;
var
  TotalTime, StartTime: Cardinal;
begin
  StartTime := GetTickCount;
  // Here your code
  TotalTime := GetTickCount - StartTime;
  ShowMessage('It took ' + IntToStr(TotalTime) + ' msec.');
end;

0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 9749505
DeNavigator,
 Sorry, maybe my question was not very clear. I was hoping for say a TLabel caption to update in real time as the procedure executed e.g. '00:00:01' - '00:00:02'... etc.

Thanks
Paul.
0
 
LVL 8

Accepted Solution

by:
gmayo earned 500 total points
ID: 9749566
Drag a TLabel and a TTimer onto your form. Then the following code will update the label with the time.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
            { Public declarations }
            Clock : integer;
      end;

var
      Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
      Inc(Clock);
      Label1.Caption := Format('%2.2d:%2.2d:%2.2d', [(Clock div 3600) mod 24, (Clock div 60) mod 60, Clock mod 60]);
end;

end.


Geoff M.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:gmayo
ID: 9749574
PS - if you are doing a processor-intensive procedure, you may want to call Application.ProcessMessages every now and again (at *least* once per second) to allow the timer to trigger.

Geoff M.
0
 
LVL 2

Expert Comment

by:DeNavigator
ID: 9749678
I created once a timer-component. If you like the code just post a comment with your email and i'll send you the sources. if you understan dutch you could have a look at this: http://www.nldelphi.com/cgi-bin/articles.exe/ShowArticle?ID=10257
I wrote this article and is describes the stopwatch component. (in dutch :) )
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 9750016
Geoff,
        Your code is exactly what I required. Simple & works perfectly.

Thanks
Paul.

P.S. Thanks also to DeNavigator.
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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
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…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

770 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