?
Solved

Simple HH:MM:SS counter

Posted on 2003-11-14
6
Medium Priority
?
362 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
  • 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
Industry Leaders: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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