Go Premium for a chance to win a PS4. Enter to Win

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

CounDown timer

i want to make Count down Timer Witch Begin From 01:00:00  hour for example and count down to 00:00:00 How to represent that in digital clock ?
0
Prof_MAM
Asked:
Prof_MAM
  • 5
  • 5
  • 3
  • +2
1 Solution
 
mokuleCommented:
Place Label and 2 buttons on a form

  private
    { Private declarations }
    StartTime: TDateTime;
    StartValue: TDateTime;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Font.Name := 'Arial';
  Label1.Font.Size := 30;
  Label1.Font.Style := [fsBold];
  Button1.Caption := 'Set';
  Button2.Caption := 'Start';
  SetTime;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetTime;
end;

procedure TForm1.SetTime;
begin
  Timer1.Enabled := False;
  StartValue := 3600./SecsPerDay; // 1 hour
  Label1.Caption := FormatDateTime('hh:nn:ss',StartValue);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled := True;
  StartTime := Now;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  str: string;
  t: TDateTime;
begin
  t := StartValue + StartTime - Now;
  if t < 0 then
    t := 0;
  str := FormatDateTime('hh:nn:ss',t);
  if str <> Label1.Caption then
    Label1.Caption := str;
end;
0
 
Ivanov_GCommented:

  one label and one timer

  {----------------------------------------------------------}

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    UpTime    : TDateTime;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  tmp : TSystemTime;
begin
  with tmp do
    begin
      // the date is not important
      wYear          := 2004;
      wMonth         := 4;
      wDayOfWeek     := 3;
      wDay           := 22;
      // initialize the time
      wHour          := 1;
      wMinute        := 0;
      wSecond        := 1;
      wMilliseconds  := 0;
    end;
  UpTime := SystemTimeToDateTime(tmp);
  UpTime := Now + Uptime;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := FormatDateTime('hh:nn:ss', UpTime - Now);
end;
0
 
ginsonicCommented:
For 200 extra points I can send you my own component what do exactly what you need. I use it ( in component ) to shut down the system after a specified time, but you can change this action to adapt for your needs.

Until then I can send a sample demo.
0
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.

 
Prof_MAMAuthor Commented:
for moukle And Ivanov_G Your Solution Are excelent but I don't want to use Labels Ineed Somthing more beatiful (For Look And fell).
For  ginsonic I am really have null Points so I can't increas the points because Ihaven't
0
 
Ivanov_GCommented:

  You can use some LED component. Take a look here :

  http://www.torry.net/pages.php?id=120

  (this is in case you want to make it look like electronic clock)
0
 
mokuleCommented:
I'm using images drawn by myself for this purpose.
They are corresponding with scoreboards I'm using.
Best draw it yourself, it's only ten digits :) and some background image.
0
 
ginsonicCommented:
Don't shout me for try :) I need points to have full access to this portal ( 3000 points/month ).

Give me your address to send the file.
0
 
sraab2004Commented:
for ginsonic
sorry for being late this is my email  
prof_mam1@hotmail.com
0
 
sraab2004Commented:
for  Ivanov_G : iam using delphi 7 and torry comonent work with d1 -d2 ...d5
0
 
Ivanov_GCommented:

   I installed Advanced Led v.1.0 on Delphi 7 without problems. I was unable to install in on D8, but on D7 it works fine.... Try it...
0
 
Prof_MAMAuthor Commented:
I installed the component successfully how to use it?
0
 
Ivanov_GCommented:

   Set the properties and handle each time tick - let's say 1000 ms - 1 seconds...
0
 
ginsonicCommented:
Read your mail.
0
 
Ivanov_GCommented:

   Sorry, my mistake. I gave you wrong component to install. Try TDynaLED v.1.0.
   It behaves like clock and have caption property, so in my code above you have to change this :

  procedure TForm1.Timer1Timer(Sender: TObject);
  begin
    DynaLED1.Caption := FormatDateTime('hh:nn:ss', UpTime - Now);
  end;
0
 
Prof_MAMAuthor Commented:
there is missing file in your packge ginsonic DsgnIntf.Dcu
0
 
ginsonicCommented:
Isn't messing. I think that you use D6 or up.
DsgnIntf is now DesignIntf
0
 
ginsonicCommented:
For messing read missing . Ups!
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.

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