Solved

Simple HH:MM:SS counter

Posted on 2003-11-14
6
346 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

18 Experts available now in Live!

Get 1:1 Help Now