Solved

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

Posted on 2004-07-30
13
206 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
 
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
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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now