Autor Beitrag
Ochsenfrosch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 75

Win 2000 Prof.
Delphi 7
BeitragVerfasst: So 18.04.04 17:09 
tachchen

ich will nen Counter machen, der bei nem bestimmten Ereignis anfängt runterzuzählen un dessen anfangszeit man mittels einen Edit feldes festlegen kann.

Kann mir einer (oder auch gerne mehrere ) Helfen??

_________________
Immer positiv denken!!!! (Windows kackt nicht ab, Windows kackt nicht ab....)
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: So 18.04.04 17:32 
Etwas simples

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:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Counter: Integer;
const
  ErrorZahl = -9999;
begin
  Counter := StrToIntDef(Edit1.Text, ErrorZahl);

  if Counter = ErrorZahl then
  begin
    Timer1.Enabled := False;
    MessageDlg('Keine Integerzahl!', mtError, [mbOk], 0);
    Exit;
  end;

  Dec(Counter);

  if Counter <= 0 then
  begin
    Timer1.Enabled := False;
    Edit1.Text := IntToStr(Counter);
    MessageDlg('Countdown beendet!', mtInformation, [mbOk], 0);
    Exit;
  end;

  Edit1.Text := IntToStr(Counter);
end;

_________________
Gruß
Martin
rokdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: So 18.04.04 18:31 
weiß nicht ob es das sit was du suchst! du zählst eine schleife nach unten und gibt immer die var aus oder was du auch immer machen willst.
sieht ungefähr so aus:for i:=10000 downto 2 do begin

hoffe das hilft dir!

robert
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: So 18.04.04 19:46 
Das geht innerhalb einer Sekunde runter.

_________________
Gruß
Martin
rokdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 329

Win XP
D6
BeitragVerfasst: So 18.04.04 19:52 
du hast recht :roll: ! könnte zwar sowas wie ei sleep noch einbauen, aber das ist dann nciht sehr guter programmstil. also Hut ab! ist ja letztendlich auch egal wie man das macht, aussser man hat eine lösung.

Robert
tmc2004
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 140

zuviele
D7,D8
BeitragVerfasst: Mo 19.04.04 15:40 
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:
type  
  TForm1 = class(TForm)  
    Button1: TButton;  
    Label1: TLabel;  
    procedure Button1Click(Sender: TObject);  
    procedure FormCreate(Sender: TObject);  
  private  
{ Private-Deklarationen }  
  public  
    procedure null;  
  end;  
  
  TMein = class(TThread)  
    procedure Execute; override;  
    procedure doit;  
  end;  
  
var  
  Form1: TForm1;  
  
implementation  
  
{$R *.DFM}  
  
var  
  t: TTime;  
  
const  
  lauf: boolean = false;  
  n = '00:00:00';  
  
procedure TMein.Execute;  
begin  
  repeat  
    if lauf then synchronize(doit);  
  until false;  
end;  
  
procedure TMein.doit;  
var rest: string;  
begin  
  with Form1 do begin  
    rest := formatdatetime('hh:nn:ss', t - frac(time));  
    if rest <> label1.caption then  
      label1.caption := rest;  
    if rest = n then begin  
      lauf := false;  
      showmessage('Zeit ist abgelaufen');  
    end;  
  end;  
end;  
  
procedure TForm1.null;  
begin  
  label1.caption := n;  
end;  
  
procedure TForm1.FormCreate(Sender: TObject);  
begin  
  null;  
  button1.caption := '&Start/Stop';  
  TMein.create(false);  
end;  
  
// Countdown für eine Stunde, fünfundzwanzig Minuten und dreißig Sekunden 
procedure TForm1.Button1Click(Sender: TObject);  
var s: string;  
begin  
  if not lauf then begin  
    s := '01:25:30';  
    lauf := true;  
    label1.caption := s;  
    t := strtotime(s) + time + 0.00001;  
  end else begin  
    lauf := false;  
    null;  
  end;  
end;


Gruß
tmc

_________________
it's not a bug it's a feature
Ochsenfrosch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 75

Win 2000 Prof.
Delphi 7
BeitragVerfasst: Di 20.04.04 14:45 
Titel: Danke
Danke Leute, Danke ich probiers mal aus....

_________________
Immer positiv denken!!!! (Windows kackt nicht ab, Windows kackt nicht ab....)
Ochsenfrosch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 75

Win 2000 Prof.
Delphi 7
BeitragVerfasst: So 25.04.04 12:07 
Titel: son mist
also irgendwie will des net klappen, hat vieleicht einer ein Beispielprogramm (dpr-datei usw.)?

mfg

Ochsenfrosch

_________________
Immer positiv denken!!!! (Windows kackt nicht ab, Windows kackt nicht ab....)
mick
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Di 21.12.04 16:36 
der code von tmc2004 klappt prinzipiell wunderbar, aber diese anweisung

ausblenden Delphi-Quelltext
1:
2:
const
  lauf: boolean = false;


ist doch quatsch, oder? lauf darf keine konstante sein, da man ihr weiter unten doch werte zuweist. sollte es nicht heissen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
{ ... }
    procedure doit;
  end;

const
  n = '00:00:00';

var
  Form1: TForm1;
  t: TTime;
  lauf: boolean = false;

implementation

{$R *.dfm}
{...}
?


ciao,
mijozi.
Pdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7
BeitragVerfasst: Di 21.12.04 16:59 
Hi
Ich selbst arbeite jha auch noch nich Lange mit delphi, aber so was kann ich schon
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:
unit Unit1;

interface

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

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

var
  Form1: TForm1;
  Zahl: integer;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.enabled:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Zahl:=strtoint(edit1.Text);
timer1.enabled:=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Zahl:=Zahl-1;
label1.caption:='Nur noch: '+inttostr(Zahl);
if Zahl=0 then showmessage(edit1.text+' Sekunden sind vergangen!Countdown beendet!');
end;

end.

Dafür brauchste nen label nen timer nen button ein editfeld

PDD

_________________
Wenn alles steht und nix mehr looft, denn isses was von Meikrosooft
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Di 21.12.04 17:33 
Pdd hat folgendes geschrieben:
Ich selbst arbeite jha auch noch nich Lange mit delphi, aber so was kann ich schon
Dafür brauchste nen label nen timer nen button ein editfeld


Pfui!!! Mit einem TTimer. Und dann auch noch den Wert beim TimerEvent abziehen. Das ist extrem ungenau.

_________________
Ciao, Sprint.
Pdd
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7
BeitragVerfasst: Di 21.12.04 18:03 
Sprint hat folgendes geschrieben:

Pfui!!! Mit einem TTimer. Und dann auch noch den Wert beim TimerEvent abziehen. Das ist extrem ungenau.

Ich sagte ja ,dass ich noch nicht lange mit delphi arbeite ich bin grad dabei zu lernen wei man eine txt datei ausließt,schreibt! :!:

_________________
Wenn alles steht und nix mehr looft, denn isses was von Meikrosooft
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 21.12.04 18:48 
Das mit dem ungenauen Timer finde ich auch dermaßen zum *******... Ich meine, wozu eine Timerkomponente, die dann doch nichts mit nem Timer zu tun hat (Timer=Zeitangeber..?)

Macht man sowas dan mit GetTickCount? von wegen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var x,y:integer;
begin
x:=GetTickCount;
y:=0;
while (y-1000)<x do y:=GetTickCount;
showmessage('1 Sekunde vergangen!');
end;


GetTickCount liefert ja die zeit in 1000stel sekunden... Klappt, so wie ich das sehe, aber saugt doch sicher speicher/performance? muss man ein Application.ProcessMessages einbauen, damit nicht gleich alles tot ist? Oha! grade ausprobiert... ja muss man.. Application.ProcessMEssages; in die schleife rein...

Aber das Prog lässt sich nicht beenden... also keine gute Idee als Timer... Kann man sowas denn nicht ordentlich lösen??

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
mick
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Do 30.12.04 00:00 
tmc2004 hat folgendes geschrieben:
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:
type  
  TForm1 = class(TForm)  
    Button1: TButton;  
    Label1: TLabel;  
    procedure Button1Click(Sender: TObject);  
    procedure FormCreate(Sender: TObject);  
  private  
{ Private-Deklarationen }  
  public  
    procedure null;  
  end;  
  
  TMein = class(TThread)  
    procedure Execute; override;  
    procedure doit;  
  end;  
  
var  
  Form1: TForm1;  
  
implementation  
  
{$R *.DFM}  
  
var  
  t: TTime;  
  
const  
  lauf: boolean = false;  
  n = '00:00:00';  
  
procedure TMein.Execute;  
begin  
  repeat  
    if lauf then synchronize(doit);  
  until false;  
end;  
  
procedure TMein.doit;  
var rest: string;  
begin  
  with Form1 do begin  
    rest := formatdatetime('hh:nn:ss', t - frac(time));  
    if rest <> label1.caption then  
      label1.caption := rest;  
    if rest = n then begin  
      lauf := false;  
      showmessage('Zeit ist abgelaufen');  
    end;  
  end;  
end;  
  
procedure TForm1.null;  
begin  
  label1.caption := n;  
end;  
  
procedure TForm1.FormCreate(Sender: TObject);  
begin  
  null;  
  button1.caption := '&Start/Stop';  
  TMein.create(false);  
end;  
  
// Countdown für eine Stunde, fünfundzwanzig Minuten und dreißig Sekunden 
procedure TForm1.Button1Click(Sender: TObject);  
var s: string;  
begin  
  if not lauf then begin  
    s := '01:25:30';  
    lauf := true;  
    label1.caption := s;  
    t := strtotime(s) + time + 0.00001;  
  end else begin  
    lauf := false;  
    null;  
  end;  
end;


Gruß
tmc



1)
wie kann ich diesen code mit 100stel oder gar 1000stel sekunden genauigkeit haben? was muss ich wie aendern?

2)
wie muesste eine code-ergaenzung aussehen, wenn ich parallel ein weiteres edit-feld haben wollte, wo von 00:00:00 an ein zaehler mit hochlaeuft und so die zeit "zaehlt" die seit dem aktivieren des countdowns vergangen ist (quasi eine stoppuhr)?


ciao,
mijozi.


Zuletzt bearbeitet von mick am Do 30.12.04 00:11, insgesamt 1-mal bearbeitet
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 30.12.04 00:10 
setze timer1.interval := 10; <- das wären also 10 millisekunden
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 30.12.04 00:12 
Wie war das? *Pfui* TTimer und Ungenau und alles? kann man vll meinen code in nen Thread packen oder sowas? (ich kenn mich mit threads mal voll ned aus ^^ noch NIE was damit gemacht oder mich damit befasst...)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Do 30.12.04 16:57 
mal was einfaches zum Thema countdown:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer1Timer(Sender: TObject);
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;

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mick
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Fr 31.12.04 15:20 
1)
wie muesste eine code-ergaenzung aussehen, wenn ich parallel ein weiteres edit-feld haben wollte, wo von 00:00:00 an ein zaehler mit hochlaeuft und so die zeit "zaehlt" die seit dem aktivieren des countdowns vergangen ist (quasi eine stoppuhr)?

2)
wozu dient der befehl "Null;" im code? was bewirkt er? was waere, wenn man ihn wegliesse?


ciao,
mijozi.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 31.12.04 15:23 
mick hat folgendes geschrieben:
tmc2004 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
 
  public  
    procedure null;  
  end;  
{...}
  
procedure TForm1.null;  
begin  
  label1.caption := n;  
end;





Da siehst du was die Procedure Null bringt ^^

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
mick
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 159



BeitragVerfasst: Sa 01.01.05 14:22 
oh, gott bin ich bloed - den teil hatte ich in meiner adaption des codes ja rausgeschnitten, nur den prozeduraufruf hatte ich drin gelassen und konnte ihn dann nicht mehr zuordnen... war wohl ein anflug von neujahrs-dusseligkeit...

damit bliebe nur noch eine offene frage 1).


ciao,
mijozi.
Dieses Thema ist gesperrt, Du kannst keine Beiträge editieren oder beantworten.

Das Thema wurde von einem Team-Mitglied geschlossen. Wenn du mit der Schließung des Themas nicht einverstanden bist, kontaktiere bitte das Team.