Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-07-30
13
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 17

Expert Comment

by:Aleksandar Bradarić
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:Aleksandar Bradarić
ID: 11684322
a stopwatch? :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:Aleksandar Bradarić
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:Aleksandar Bradarić
Aleksandar Bradarić earned 400 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 100 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:Aleksandar Bradarić
ID: 11750199
:)
0
 
LVL 3

Author Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

609 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