Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Lokking for Countdown component

Posted on 1999-07-04
22
Medium Priority
?
355 Views
Last Modified: 2010-05-18
Howdy folks,

I'm looking for a simple Countdown component, which will count down from the specified time...

Being the self-centered egotistical bastard that I am, I have little time to go searching through DSP, Torry's delphi pages and all the rest of them...

I would appreciate it if somebody knows where the component is, and would tell me..

thanks....

x
0
Comment
Question by:X_Kalibur
[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
  • 12
  • 9
22 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386125
Here is a component I wrote. Install it with  Component menu > Install Component > browse for the .pas file where you save the source below in.

It is derived from TLabel and I added an Interval property in it. The other properies behave like TLabel's except Caption.



Methods:

TCountDown.StartCountDown(value);
TCountDown.StopCoundown;
TCountDown.Resume
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386126
unit CountDown;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, extctrls;

type              
  TCountDown = class(TLabel)
  private
    { Private declarations }
    timer: TTimer;
    FInterval: Integer;    
    counter: Integer;
    procedure SetInterval(const Value: Integer);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure StartCountDown(value: Integer);
    procedure StopCountDown;
    procedure ResumeCountDown;
    procedure TimerEvent(Sender: TObject);
  published
    { Published declarations }
    property Interval: Integer read FInterval write SetInterval default 1000;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Epsylon', [TCountDown]);
end;

{ TCountDown }

constructor TCountDown.Create(AOwner: TComponent);
begin
  inherited;
  FInterval := 1000;
  timer := TTimer.Create(Self);
  timer.Enabled := false;
  timer.OnTimer := TimerEvent;
end;

destructor TCountDown.Destroy;
begin
  timer.Free;
  inherited;
end;

procedure TCountDown.StartCountDown(value: Integer);
begin
  counter := value;
  with timer do
  begin
    Caption := IntToStr(counter);
    Enabled := true;
  end;
end;

procedure TCountDown.StopCountDown;
begin
  timer.Enabled := false;
end;

procedure TCountDown.ResumeCountDown;
begin
  timer.Enabled := true;
end;

procedure TCountDown.TimerEvent(Sender: TObject);
begin
  Dec(counter);
  Caption := IntToStr(counter);
  if counter = 0 then
    timer.Enabled := false;
end;

procedure TCountDown.SetInterval(const Value: Integer);
begin
  FInterval := Value;
  timer.Interval := FInterval;
end;

end.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386127
I have extended it a little so it will display like:

00:15:24

New properties:

Interval: time in millisecond
DisplayTime: whether or not display like 00:15:24
DisplayFormat: String that contains the time format (h:mm:ss)


Methods:

TCountDown.StartCountDown(value: integer);  value in seconds
TCountDown.StartCountDown(value: String); value like '00:15:24'
TCountDown.StopCoundown;
TCountDown.Resume;


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 13

Expert Comment

by:Epsylon
ID: 1386128
unit CountDown;

interface

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

type              
  TCountDown = class(TLabel)
  private
    { Private declarations }
    timer: TTimer;
    counter: Integer;
    FInterval: Integer;
    FDisplayFormat: String;
    FDisplayTime: Boolean;
    procedure SetInterval(const Value: Integer);
    procedure SetDisplayFormat(const Value: String);
    procedure SetDisplayTime(const Value: Boolean);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure StartCountDown(value: Integer); overload;
    procedure startCountDown(value: String); overload;
    procedure StopCountDown;
    procedure ResumeCountDown;
    procedure TimerEvent(Sender: TObject);
  published
    { Published declarations }
    property Interval: Integer read FInterval write SetInterval;
    property DisplayFormat: String read FDisplayFormat write SetDisplayFormat;
    property DisplayTime: Boolean read FDisplayTime write SetDisplayTime;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Epsylon', [TCountDown]);
end;

{ TCountDown }

constructor TCountDown.Create(AOwner: TComponent);
begin
  inherited;
  FInterval := 1000;
  FDisplayFormat := 'h:mm:ss';
  FDisplayTime := true;
  timer := TTimer.Create(Self);
  timer.Enabled := false;
  timer.OnTimer := TimerEvent;
end;

destructor TCountDown.Destroy;
begin
  timer.Free;
  inherited;
end;

procedure TCountDown.StartCountDown(value: Integer);
begin
  counter := value;
  with timer do
  begin
    Caption := IntToStr(counter);
    Enabled := true;
  end;
end;

procedure TCountDown.StartCountDown(value: String);
begin
  counter := Trunc(StrToTime(value) * 86400);
  with timer do
  begin
    Caption := IntToStr(counter);
    Enabled := true;
  end;
end;

procedure TCountDown.StopCountDown;
begin
  timer.Enabled := false;
end;

procedure TCountDown.ResumeCountDown;
begin
  timer.Enabled := true;
end;

procedure TCountDown.TimerEvent(Sender: TObject);
begin
  Dec(counter);
  if FDisplayTime then
    Caption := TimeToStr(counter / 86400)
  else
    Caption := IntToStr(counter);
  if counter = 0 then
    timer.Enabled := false;
end;

procedure TCountDown.SetInterval(const Value: Integer);
begin
  FInterval := Value;
  timer.Interval := FInterval;
end;

procedure TCountDown.SetDisplayFormat(const Value: String);
begin
  FDisplayFormat := Value;
  ShortTimeFormat := FDisplayFormat;
end;

procedure TCountDown.SetDisplayTime(const Value: Boolean);
begin
  FDisplayTime := Value;
end;

end.
0
 

Expert Comment

by:sorry
ID: 1386129
Hi, Kalibur

 try a component call supertimer, I am using it now, it is very nice:
http://www.ping.be/jg

Hope it help you.

Rgds

James
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386130
Thanks fellars....

I've taken both of your ideas down, and i'm going to see which one works the best...

I'm actually leaning more towards Epsylon, because the component he wrote, means that it can be easily modified (If he'll give me the rights do do so ;)

thanks again, to boht of you and i'll give the 100 points to whicever works the best :)


-x

PS...Yeh, I increased the number of points to 100, because i figured it must have taken a while to find this stuff.. :)

thanks again

-x
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386131
Adjusted points to 100
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386132
If you like me to enhance the component, just ask   :o)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386133
No restrictions apply to it. Do with it what you want.....
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386134
Errr....Epsylon,


First of all, i want to say that i've never made my own compoent, and i'm not too sure how to write VCL's...but I've tried using your component, and it wont compile.

I tried many things to get it working (IE: Making a new compoenent and copying the code, importing the unit etc...), but still to no avail..

Its been ginving me quite a few error messages...They are:

(Line 12) Undelcared Identifier : TTimer
(Line 25) Field Definition not allowed after methods or properties

and then it gives unknown directives and identifier error messages..

I tried using James suggestion and it has worked fine...I'd really like to give you the points, if i could get this component working, but i also have finite time to work within, and if i cant, i'll have to take the alternative option.....sorry..

thankx,

x
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386135
Which delphi versin do you have?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386136
It must be 3 or below. Here is what went wrong:

Line 12: TTimer is difined in ExtCtrls. I included it in my source so you must have forgotten it.

Line 25: Delphi 3 and below do not support method overloading.


Fixes:

one of the StartCoundown methods is now called StartCountdownEx.


New enhancements:

OnTakeOffEvent   :o)    fired when zero is reached.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386137
unit CountDown;

interface

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

type
  TTakeOffEvent = procedure(Sender: TObject) of object;

  TCountDown = class(TLabel)
  private
    { Private declarations }
    timer: TTimer;
    counter: Integer;
    FInterval: Integer;
    FDisplayFormat: String;
    FDisplayTime: Boolean;
    FOnTakeOff: TTakeOffEvent;
    procedure SetInterval(const Value: Integer);
    procedure SetDisplayFormat(const Value: String);
    procedure SetDisplayTime(const Value: Boolean);
    procedure DrawCounter(Value: Integer);
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure StartCountDown(value: Integer);
    procedure startCountDownEx(value: String);
    procedure StopCountDown;
    procedure ResumeCountDown;
    procedure TimerEvent(Sender: TObject);
  published
    { Published declarations }
    property Interval: Integer read FInterval write SetInterval;
    property DisplayFormat: String read FDisplayFormat write SetDisplayFormat;
    property DisplayTime: Boolean read FDisplayTime write SetDisplayTime;
    property OnTakeOff: TTakeOffEvent read FOnTakeOff write FOnTakeOff;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Epsylon', [TCountDown]);
end;

{ TCountDown }

constructor TCountDown.Create(AOwner: TComponent);
begin
  inherited;
  FInterval := 1000;
  FDisplayFormat := 'h:mm:ss';
  FDisplayTime := true;
  timer := TTimer.Create(Self);
  timer.Enabled := false;
  timer.OnTimer := TimerEvent;
end;

destructor TCountDown.Destroy;
begin
  timer.Free;
  inherited;
end;

procedure TCountDown.StartCountDown(value: Integer);
begin
  counter := value;
  with timer do
  begin
    DrawCounter(counter);
    Enabled := true;
  end;
end;

procedure TCountDown.StartCountDownEx(value: String);
begin
  counter := Trunc(StrToTime(value) * 86400);
  with timer do
  begin
    DrawCounter(counter);
    Enabled := true;
  end;
end;

procedure TCountDown.StopCountDown;
begin
  timer.Enabled := false;
end;

procedure TCountDown.ResumeCountDown;
begin
  timer.Enabled := true;
end;

procedure TCountDown.TimerEvent(Sender: TObject);
begin
  Dec(counter);
  DrawCounter(counter);
  if counter = 0 then
  begin
    timer.Enabled := false;
    if Assigned(FOnTakeOff) then FOnTakeOff(Self);
  end;
end;

procedure TCountDown.SetInterval(const Value: Integer);
begin
  if Value <> FInterval then
  begin
    FInterval := Value;
    timer.Interval := FInterval;
  end;
end;

procedure TCountDown.SetDisplayFormat(const Value: String);
begin
  if Value <> FDisplayFormat then
  begin
    FDisplayFormat := Value;
    ShortTimeFormat := FDisplayFormat;
  end;
end;

procedure TCountDown.SetDisplayTime(const Value: Boolean);
begin
  FDisplayTime := Value;
end;

procedure TCountDown.DrawCounter(Value: Integer);
begin
  if FDisplayTime then
    Caption := TimeToStr(counter / 86400)
  else
    Caption := IntToStr(counter);
end;

end.
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386138
Epsylon,

Yeh, I have Delphi 3, STD.

Hang on...I'm gonna try out your new source.

0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386139
Yeeee Haw!

It works!

Thanks a tonne dude...This looks really good...I'm gooing to have to learn how you did it...BTW...I like the function of converting the ms to hrs, mins, sec...Its very handy, cause i would had to have written my own, otherwise :)

Thakns alot, again..I'll give you the points, as soon as you lodge an official answer....

One last thing,.... do you know any REALLY good resources on the net, which will give me the best kick start into VCL coding?? Its something which has intrigued me, but i have never had the chance to learn how to do it...

thanks again,

x
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 400 total points
ID: 1386140
Glad you like it x    :o)

Please grade me 'A' for maximum points (100 x 4).

I will check for resources on the net but I got the most from the help files.

Thanks a lot.
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386141
Epsylon,

You mean the Delphi Help files? I remember Delphi 1 came with a small booklet called The Component Writes' Guide...But damned if i could find it now!
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386142
Whoops!

sorry...forgot to grade answer :)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386143
Yes, I mean the Delphi help files... Delphi 3 is where I started....
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386144
excellent...

well i'll have to give them a look into..

Thanks again, dude

-x
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1386145
No problem, I hope you are familiar enough with Object Oriented Programming because that is of major importance. Looking at other sources and examples is IMO the best way to learn. Learn by doing!
You can always ask your specific questions here on E-E.

Cheers,

Epsylon.
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1386146
hehe

can do!

thankx

-x
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…
Suggested Courses

660 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