Registriert seit: 7. Dez 2008
70 Beiträge
|
Uhr nach zeiteingabe läuft nicht
22. Jan 2009, 21:10
Hallo!
Leider läuft meine uhr nicht nach eingabe meiner zeit...
dacht das macht der ttimer...
Delphi-Quellcode:
var mx,my:integer;
hour, min, sec, msec : byte;
zeile: string;
MyTime: TDatetime;
//Uhrzeit stellen-----------------------------------------------
Procedure TForm2.Zeit;
begin
zeile := EdUhr.Text;
try
hour := StrtoInt(copy(zeile,1,2));
Min := StrtoInt(copy(zeile,4,2));
Sec := StrtoInt(copy(zeile,7,2));
except
ShowMessage('Falsche Eingabe');
exit;
end;
if hour >= 24 then hour := 0;
if Min >= 60 then Min := 0;
if Sec >= 60 then Sec := 0;
MyTime := EncodeTime(hour,min,sec,msec);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Zeit;
end;
//digtaluhr und mitte bestimmen--------------------------------
procedure TForm2.Timer1Timer(Sender: TObject);
var winkel : real;
x, y, r, i: Integer;
hour, min, sec, msec : Word;
begin
Form2.Caption:=TimeToStr(mytime);
decodetime(mytime,hour,min,sec,msec);
r:=((mx+my)div 4);
mx := Width div 2;
my := Height div 2;
refresh;
//Stundenstriche ------------------------------------------
with canvas do begin
pen.Width:=3;
pen.Color:=clblack;
moveto(mx,my-width div 4);
lineto(mx,my-width div 5);
pen.Width:=3;
pen.Color:=clblack;
moveto(mx-width div 4,my);
lineto(mx-width div 5,my);
pen.Width:=3;
pen.Color:=clblack;
moveto(mx+width div 4,my);
lineto(mx+width div 5,my);
pen.Width:=3;
pen.Color:=clblack;
moveto(mx,my+width div 4);
lineto(mx,my+width div 5);
// Sekundenzeiger------------------------------------------
winkel:=sec* ((2*pi) / 60) - pi/2;
x:=Trunc(cos(winkel)*r);
y:=Trunc(sin(winkel)*r);
x:=x+(mx);
y:=y+(my);
Canvas.Pen.Color:=clblack;
Canvas.Pen.Width:=1;
Canvas.MoveTo(mx,my);
Canvas.LineTo(x,y);
//Minutenzeiger------------------------------------------
winkel:=min* ((2*pi) / 60) - pi/2;
x:=Trunc(cos(winkel)*r*0.9);
y:=Trunc(sin(winkel)*r*0.9);
x:=x+(mx);
y:=y+(my);
Canvas.Pen.Width:=2;
Canvas.MoveTo(mx,my);
Canvas.LineTo(x,y);
//Stundenzeiger------------------------------------------
IF hour>12 THEN hour:=hour-12;
winkel:=(hour*(2*pi) / 12) + (min*(2*pi) / 720) - pi/2;
x:=Trunc(cos(winkel)*r*0.8);
y:=Trunc(sin(winkel)*r*0.8);
x:=x+(mx);
y:=y+(my);
Canvas.Pen.Width:=3;
Canvas.MoveTo(mx,my);
Canvas.LineTo(x,y);
end;
end;
end.
Meine Version:
Borland® Delphi® für Microsoft® Windows™ Version 10.0.2288.42451 Update 2 Copyright © 2005 Borland® Software Corporation.
|