Autor Beitrag
maveric
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 54


D7
BeitragVerfasst: Sa 26.03.05 19:55 
Hallo Zusammen,
Ich brauche ein countdown für mein Programm.

Ich hab mal mich mal schlau gemacht und hab folgendes gefunden :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var zeit: array[1..2] of tTime;
begin
zeit[1]:=time;
zeit[2]:=strtotime('17:00:00');
label1.Caption:=timetostr(zeit[2]-zeit[1]);
end;



Das ist schon ganz net, leider gibt es nur die Uhrzeit an.

Wie kann ich den z.B. von '00:01:00'

auf Null herunterzählen ??? und das dan auch noch in einem label visualisieren ??

Danke maveric

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 26.03.05 20:34 
Beim Start speicherst du dir StartTime := Now in eine temporäre Variable. Die verbleibende Zeit erhältst du dann mit strtotime(1/24/3600-(Now-StartTime)) (Beispiel 1h).
maveric Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 54


D7
BeitragVerfasst: So 27.03.05 23:29 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var Starttime,now:ttime;
begin
  Starttime:=strtotime('00:01:00');
  Starttime:=now;
  label1.caption:=timetostr(1/24/3600-(Now-StartTime)) ;
end;

so weit bin ich jetzt. Kann noch nicht funktieren, im mom zeigt er mir im label konstant 00:00:01 an!

Was muss ich denn noch tun um dat Ding zum Laufen zu bekommen , so das er von 1 Min auf Null zählt und die Veränderung auch im Label anzeigt ????

Schleife ???

Bitte um Hilfe

Danke

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt.
SandTarnFarbe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP, Win 2003 Server
D7 Pers
BeitragVerfasst: Mo 28.03.05 00:10 
Logisch wenn du hintereinander StartTime jedesmal überschreibst - hoffe mal der gesamte Code steht in einem Timer!?
user profile iconmaveric hat folgendes geschrieben:

Starttime:=strtotime('00:01:00');
Starttime:=now;


Und so gehts:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
unit Unit1;

interface

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

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

var
  Form1: TForm1;
  StartTime: TTime;
implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := TimeToStr (1 / 24 / 3600 - (Now - StartTime));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StartTime := StrToTime ('00:01:00') + Now;
end;

end.
maveric Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 54


D7
BeitragVerfasst: Mo 28.03.05 13:01 
Also bitte, natürlich steht das im Timer.

War mir ja klar das das nicht funzt.

Hier ist nun mein countdown, nun peept er auch noch die letzten 5 sec., könnte man vielleicht noch schöner schreiben, aber es geht !


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);


  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  StartTime: TTime;

implementation

{$R *.dfm}



procedure TForm1.Timer1Timer(Sender: TObject);
 var i: integer;
begin
  Label1.Caption := TimeToStr (1 / 24 / 3600 - (Now - StartTime));

  if label1.caption = '00:00:05'
    then
      begin
        beep;
      end;

  if label1.caption = '00:00:04'
    then
      begin
        beep;
      end;

  if label1.caption = '00:00:03'
    then
      begin
        beep;
     end;

  if label1.caption = '00:00:02'
    then
      begin
        beep;
      end;

  if label1.caption = '00:00:01'
   then
      begin
        beep;
      end;

  if label1.caption = '00:00:00'
    then
      begin
        windows.beep(1000,500);;
        timer1.enabled:=false;
      end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StartTime := StrToTime ('00:00:10') + Now;
end;

end.
SandTarnFarbe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26

Win XP, Win 2003 Server
D7 Pers
BeitragVerfasst: Mo 28.03.05 13:30 
lass doch das "then begin beep end" weg und schreib nur .... then beep;
macht das gleiche!
Bumpy Johnson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mo 28.03.05 13:37 
hi,

ich bin auch gerade dabei ein Timer zu schreiben. Meiner basiert aber darauf, dass der Benutzer selber eine (Minuten) Eingabe macht... Ich wollte euch einfach noch mal eine ALternative zeigen! Könnt mal rein schauen und sagen wie sie euch gefällt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
unit mainunit;

interface

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

type
  Tfrmmain = class(TForm)
    Edit1: TEdit;
    Timer1: TTimer;
    lbzeit: TLabel;
    Image1: TImage;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Label1: TLabel;
    sbtnstart: TSpeedButton;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private-Deklarationen }
    starttime, min, sec, hours, ms: integer;
    i,z : integer;
  public
    { Public-Deklarationen }
  end;

var
  frmmain: Tfrmmain;

implementation

{$R *.dfm}

procedure Tfrmmain.Timer1Timer(Sender: TObject);
begin


sec := sec - 1;

if length(inttostr(sec)) = 2 then lbzeit.Caption := inttostr(min)+':'+inttostr(sec) else lbzeit.Caption := inttostr(min)+':0'+inttostr(sec);


if (min = 0) and (sec = 0)then begin
timer1.Enabled := false;
exit;
end;

{if ms = 0 then begin
sec := sec - 1;
ms := 10;
end;}


if sec = 0 then begin
min := min - 1;
sec := 60;
end;


end;

procedure Tfrmmain.Button1Click(Sender: TObject);
begin
starttime := strtoint(edit1.text);
min := starttime - 1;
sec := 60;
ms := 10;

timer1.Enabled := true;


end;

_________________
-Bumpy Johnson
rest in Peace