[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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

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
lopem
Asked:
lopem
  • 5
  • 4
  • 3
  • +1
2 Solutions
 
Aleksandar BradarićSoftware DeveloperCommented:
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
 
tobjectpascalCommented:
without sounding too stupid what is a "chronometer" :)
0
 
Aleksandar BradarićSoftware DeveloperCommented:
a stopwatch? :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lopemAuthor Commented:
Hi, Leannonn,

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

By the way, any example code about your idea?

best wishes,
Manuel
0
 
Aleksandar BradarićSoftware DeveloperCommented:
> By the way, any example code about your idea?

I could put together some code... Simple display, nothing fancy, right?
0
 
lopemAuthor Commented:
yes, let see three or four stopwatch at the same time. Please... :)

Thanks a lot
Manuel
0
 
mokuleCommented:
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
 
Aleksandar BradarićSoftware DeveloperCommented:
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
 
tobjectpascalCommented:
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
 
tobjectpascalCommented:
Well i thought my example is what you needed, no feedback on it though...
0
 
tobjectpascalCommented:
?
0
 
Aleksandar BradarićSoftware DeveloperCommented:
:)
0
 
lopemAuthor Commented:
Thanks a lot!
best wishes
Manuel Lopez (Lopem)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now