Solved

using a chronometer and how many instances of it can I have...

Posted on 2004-07-30
13
210 Views
Last Modified: 2012-05-05
Hi guys,

I am looking for a chronometer component (shareware or freeware. Anybody knows where to find a good one?). I need to add to my form between 15-20 chronometers. They must act each one separately. I don't know if delphi can accept some many instances of this component. I guess not (normally a chrono component will use the timer component, and I am pretty sure there is a limit of timers in a form activated).  So, is there a way to add -let say 15- chronometers and use them independently?

best regards
Manuel Lopez (lopem)
0
Comment
Question by:lopem
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 17

Expert Comment

by:leannonn
ID: 11683899
You could use one Timer coponent and an array of 15 DateTime variables. Each of these would hold the start time for one chronometer. The Timer would update data for all chronometers...
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 11684302
without sounding too stupid what is a "chronometer" :)
0
 
LVL 17

Expert Comment

by:leannonn
ID: 11684322
a stopwatch? :)
0
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.

 
LVL 3

Author Comment

by:lopem
ID: 11684903
Hi, Leannonn,

Yes, chronometer is another name for a stopwatch... :)

By the way, any example code about your idea?

best wishes,
Manuel
0
 
LVL 17

Expert Comment

by:leannonn
ID: 11684980
> By the way, any example code about your idea?

I could put together some code... Simple display, nothing fancy, right?
0
 
LVL 3

Author Comment

by:lopem
ID: 11685058
yes, let see three or four stopwatch at the same time. Please... :)

Thanks a lot
Manuel
0
 
LVL 17

Expert Comment

by:mokule
ID: 11685699
Look at
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21066382.html
I've posted there complete working example of stopwatch.
There is only one but it can be easy expanded to any desired 10 or 100
0
 
LVL 17

Assisted Solution

by:leannonn
leannonn earned 100 total points
ID: 11687076
Hi,

Here's some sample code. Click on any timer to reset it...

--- [ begin:: Unit1.pas ] ---
unit Unit1;

interface

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

const
  maxCnt                  = 15;
  fmtDisplay              = 'nn:ss:zzz'; { 'hh:nn:ss'; }

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    Panel8: TPanel;
    Panel9: TPanel;
    Panel10: TPanel;
    Panel11: TPanel;
    Panel12: TPanel;
    Panel13: TPanel;
    Panel14: TPanel;
    Panel15: TPanel;
    Timer1: TTimer;
    procedure Panel1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    StartDT               : Array[1..15] of TDateTime;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Panel1Click(Sender: TObject);
begin
  { Reset the panel's timer... }
  StartDT[(Sender as TPanel).Tag] := Now;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Cnt             : Integer;

begin
  Timer1.Enabled := False;
  { Update all panels... }
  For Cnt := 1 to maxCnt do
    (FindComponent('Panel' + IntToStr(Cnt)) as TPanel).Caption := FormatDateTime(fmtDisplay, Now - StartDT[Cnt]);
  Timer1.Enabled := True;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  tmpNow          : TDateTime;
  Cnt             : Integer;

begin
  tmpNow := Now;
  For Cnt := 1 to maxCnt do
    StartDT[Cnt] := tmpNow;
  Timer1.Enabled := True;
end;

end.
--- [ end:: Unit1.pas ] ---

--- [ begin:: Form1.dfm ] ---
object Form1: TForm1
  Left = 274
  Top = 202
  Width = 337
  Height = 175
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Shell Dlg 2'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Tag = 1
    Left = 8
    Top = 16
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 0
    OnClick = Panel1Click
  end
  object Panel2: TPanel
    Tag = 2
    Left = 72
    Top = 16
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 1
    OnClick = Panel1Click
  end
  object Panel3: TPanel
    Tag = 3
    Left = 136
    Top = 16
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 2
    OnClick = Panel1Click
  end
  object Panel4: TPanel
    Tag = 4
    Left = 200
    Top = 16
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 3
    OnClick = Panel1Click
  end
  object Panel5: TPanel
    Tag = 5
    Left = 264
    Top = 16
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 4
    OnClick = Panel1Click
  end
  object Panel6: TPanel
    Tag = 6
    Left = 8
    Top = 56
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 5
    OnClick = Panel1Click
  end
  object Panel7: TPanel
    Tag = 7
    Left = 72
    Top = 56
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 6
    OnClick = Panel1Click
  end
  object Panel8: TPanel
    Tag = 8
    Left = 136
    Top = 56
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 7
    OnClick = Panel1Click
  end
  object Panel9: TPanel
    Tag = 9
    Left = 200
    Top = 56
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 8
    OnClick = Panel1Click
  end
  object Panel10: TPanel
    Tag = 10
    Left = 264
    Top = 56
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 9
    OnClick = Panel1Click
  end
  object Panel11: TPanel
    Tag = 11
    Left = 8
    Top = 96
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 10
    OnClick = Panel1Click
  end
  object Panel12: TPanel
    Tag = 12
    Left = 72
    Top = 96
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 11
    OnClick = Panel1Click
  end
  object Panel13: TPanel
    Tag = 13
    Left = 136
    Top = 96
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 12
    OnClick = Panel1Click
  end
  object Panel14: TPanel
    Tag = 14
    Left = 200
    Top = 96
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 13
    OnClick = Panel1Click
  end
  object Panel15: TPanel
    Tag = 15
    Left = 264
    Top = 96
    Width = 57
    Height = 33
    Cursor = crHandPoint
    Caption = '00:00:00'
    TabOrder = 14
    OnClick = Panel1Click
  end
  object Timer1: TTimer
    Enabled = False
    Interval = 20
    OnTimer = Timer1Timer
    Left = 56
    Top = 8
  end
end
--- [ end:: Form1.dfm ] ---

Hope it helps :)
0
 
LVL 4

Accepted Solution

by:
tobjectpascal earned 25 total points
ID: 11687764
i wrote a stopwatch inheriting the label, let me find it.

I know it's pretty sad but i wrote this when i was first learning how
to use objects, but if this helps great :)

unit MyLabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls,ExtCtrls;

type
  TMyLabel = class(TLabel)
  private
    { Private declarations }
   MyTimer: TTimer;
   FTimeTaken: Real;
   procedure Timer1Timer(Sender: TObject);
  protected
   StartT,EndT: Longint;
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: Tcomponent); override;
    destructor Destroy; override;
    Procedure StartTimer;
    Procedure StopTimer;
  published
    { Published declarations }
     property TimeTaken: Real Read FTimeTaken Write FTimeTaken;
  end;

procedure Register;


implementation


Procedure TmyLabel.StopTimer;
Begin
  MyTimer.Enabled:=False;
End;

destructor TmyLabel.Destroy;
begin
  inherited;
  MyTimer.Free;
end;

constructor TMYLabel.Create(AOwner:TComponent);
begin
   inherited;
   TimeTaken:=0;
   MyTimer:=TTimer.Create(nil);
   MyTimer.Interval:=1;
   MyTimer.Enabled:=False;
   MyTimer.OnTimer:=Timer1Timer;
end;

procedure TmyLabel.Timer1Timer(Sender: TObject);
Begin
// Caption:=IntToStr(Random(122323));
   EndT:=GetTickCount;
   TimeTaken:=(EndT-StartT)/1000;
   Caption:=FloatToStr(TimeTaken);
End;

Procedure TmyLabel.StartTimer;
Begin
  TimeTaken:=0;
  StartT:=GetTickCount;
  MyTimer.Enabled:=True;
End;


procedure Register;
begin
  RegisterComponents('Natalia', [TMyLabel]);
end;

end.

Compile it as a component and then drop it on the form and stick
the code below in a button, you will see what it does, then
adapt it.

Begin
 MyLabel1.StartTimer;
 Sleep(1000);
 Application.ProcessMessages;
 MyLabel1.StopTimer;
 ShowMessage('Time Taken: '+FloatTOStr(MyLabel1.TimeTaken)+' Seconds');
End;
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 11692023
Well i thought my example is what you needed, no feedback on it though...
0
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 11750127
?
0
 
LVL 17

Expert Comment

by:leannonn
ID: 11750199
:)
0
 
LVL 3

Author Comment

by:lopem
ID: 11753852
Thanks a lot!
best wishes
Manuel Lopez (Lopem)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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