Solved

Simple HH:MM:SS counter

Posted on 2003-11-14
6
350 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 125 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

786 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