Hallo,
ich soll für meinen Informatikkurs eine Stoppuhr programmieren, da es egal ist, ob sie tatsächlich der Zeit getreu läuft, habe ich mich dazu entschlossen, den Delphi Timer zu benutzen. Da ich leider in den Kurs eingestiegen bin, nachdem sie schon ein halbes Jahr damit gearbeitet hatten, fehlt mir die ein oder andere Hintergrundinformation und aus der Hilfe werde ich auch nicht so richtig schlau. Meine Stoppuhr funktioniert jetzt auf die Befehle eigentlich einwandfrei, nur kann ich den Timer nicht einstellen. Die Zeit wird nur ein einzigesmal gemessen und ich weiß nicht, wie ich ihn auf onTimer einstellen muss, damit er anfängt zu zählen. Wäre super, wenn ihr mir helfen könntet.
Gruß,
Rachel
Die Zeit soll auf centiMinuten "genau" laufen. Hier ist der 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: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type tStoppuhr=class(tObject) private h: integer; m: integer; s: integer; cs: integer; f: integer; k: integer; public procedure initialisation; procedure startbutton; procedure startpause; procedure stoppbutton; procedure stoppend; function count(h,m,s,cs:integer): string; end;
type TForm1 = class(TForm) Image1: TImage; Button1: TButton; Button2: TButton; Edit1: TEdit; Timer1: TTimer; Image2: TImage; Image3: TImage; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private public stoppuhr: tStoppuhr; end;
var Form1: TForm1;
implementation
procedure tstoppuhr.initialisation; begin h:=0; m:=0; s:=0; cs:=0; f:=0; k:=0; end;
procedure tstoppuhr.startbutton; begin Form1.Timer1.enabled:=true; end;
procedure tstoppuhr.startpause; begin Form1.Timer1.enabled:=false; end;
procedure tstoppuhr.stoppbutton; begin Form1.Timer1.Enabled:=false; end;
procedure tstoppuhr.stoppend; begin Form1.timer1.enabled:=false; initialisation; end;
function tstoppuhr.count(h,m,s,cs:integer): string; begin cs:=cs+1; if cs=100 then begin cs:=0; s:=s+1; end; if s=60 then begin s:=0; m:=m+1; end; if m=60 then begin m:=0; h:=h+1; end; if h=100 then begin h:=0; m:=0; s:=0; cs:=0; end; count:=inttostr(h) + ':' + inttostr(m) + '.' + inttostr(s) + ',' + inttostr(cs); end;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject); begin stoppuhr:= tStoppuhr.create; stoppuhr.initialisation; end;
procedure TForm1.Button1Click(Sender: TObject); begin stoppuhr.f:=stoppuhr.f+1; if stoppuhr.f=1 then stoppuhr.startbutton else if stoppuhr.f=2 then begin stoppuhr.f:=0; stoppuhr.startpause; end; end;
procedure TForm1.Button2Click(Sender: TObject); begin stoppuhr.k:=stoppuhr.k+1; if stoppuhr.k=1 then stoppuhr.stoppbutton else if stoppuhr.k=2 then begin stoppuhr.k:=0; edit1.text:='00:00.00,00'; end; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin edit1.Text:=stoppuhr.count(stoppuhr.h, stoppuhr.m, stoppuhr.s, stoppuhr.cs) end;
end. |
[list][*]