Thema: Delphi Brauche Hilfe zu Threads

Einzelnen Beitrag anzeigen

Oldjoe37

Registriert seit: 28. Dez 2007
19 Beiträge
 
Delphi 5 Enterprise
 
#6

Re: Brauche Hilfe zu Threads

  Alt 30. Dez 2007, 15:46
Bei Timer2 läuft zwar die Uhr, aber das Pendel zuckt höchstens.
Bitte über meinen Code nicht lachen, bin wirklich nur Anfänger!


Delphi-Quellcode:
unit Uhr1;

interface

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

type
   TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Timer1: TTimer;
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Pendel: TTimer;
    Timer2: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);


  private
    { Private-Deklarationen }

  end;

var
    Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Width := 210;
  Form1.Height := 452;
  Form1.Position := poScreenCenter;
  Doublebuffered := True;

end;

Procedure Berechne_Stunde(winkel: Real; var xi,yi: Integer);
var x,y:Real;
begin
  winkel := winkel - pi/2;
  x:= 134 + 31*Cos(winkel);
  y:= 150 + 31*Sin(winkel);
  xi:=Trunc(x);
  yi:=Trunc(y);
end;

Procedure Berechne_Minute(winkel:Real;var ri,si:Integer);
var r,s:Real;

begin
  winkel := winkel - pi/2;
  r:= 134 + 39*Cos(winkel);
  s:= 150 + 39*Sin(winkel);
  ri:=Trunc(r);
  si:=Trunc(s);
  If sin(winkel) = -1 then sndPlaySound(PChar('file10.wav'), SND_ASYNC);
  If sin(winkel) = 1 then sndPlaySound(PChar('file9.wav'), SND_ASYNC);
  end;

Procedure Berechne_Sekunde(winkel:Real;var ui,vi:Integer);
var u,v:Real;
begin
  winkel := winkel - pi/2;
  u:= 134 + 50*Cos(winkel);
  v:= 150 + 50*Sin(winkel);
// sndPlaySound(PChar('start.wav'), SND_ASYNC);
  ui:=Trunc(u);
  vi:=Trunc(v);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var hour,min,sec,msec:Word;
    x,y,r,s,u,v:Integer;

begin
  DecodeTime(Now,hour,min,sec,msec);
  Label1.Caption := TimeToStr(Now);
  Label2.caption := DateToStr(Now);
  Refresh;

  //Stundenzeiger
  if hour > 12 then hour:= hour - 12;
  Berechne_Stunde(2*pi/12*hour + 2*pi/720*min,x,y);
  Canvas.Pen.Width := 4;
  Canvas.Pen.Color := clBlack;
  Canvas.Moveto(134, 150);
  Canvas.LineTo(x,y);

  //Minutenzeiger
  Berechne_Minute((2*pi/60*min),r,s); // + (2*pi/3600*min)
  Canvas.Moveto(134, 150);
  Canvas.Pen.Width := 3;
  Canvas.Pen.Color := clBlack;
  Canvas.LineTo(r,s);

  //Sekundenzeiger
  Berechne_Sekunde(2*pi/60*sec,u,v);
  Canvas.Moveto(134, 150);
  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clRed;
  Canvas.LineTo(u,v);
{ ######## Das Folgende war nur ein vereinfachter Test ####
//Pendel
  Canvas.Pen.Width := 6;
  Canvas.Pen.Color := clBlack;
     if sec mod 2 = 1 then
        begin
              Refresh;
              Image3.visible:=false;
             Canvas.Moveto(139, 215);
             Canvas.LineTo(157,348);
              Image2.visible:=true;
        end
        else
        begin
                Refresh;
                Image2.visible:=false;
                Canvas.Moveto(129, 215);
              Canvas.LineTo(112,348);
                Image3.visible:=true;
        end; }

end;

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

procedure TForm1.Timer2Timer(Sender: TObject);
var hour,min,sec,msec:Word;
begin
// ######## Das Folgende ist nur ein vereinfachter Test ####
 //Pendel
  Canvas.Pen.Width := 6;
  Canvas.Pen.Color := clBlack;
     if sec mod 2 = 1 then
        begin
               Refresh;
               Image3.visible:=false;
              Canvas.Moveto(139, 215);
              Canvas.LineTo(157,348);
               Image2.visible:=true;
        end
        else
        begin
                Refresh;
                Image2.visible:=false;
                Canvas.Moveto(129, 215);
              Canvas.LineTo(112,348);
                Image3.visible:=true;
        end;
end;

end.
  Mit Zitat antworten Zitat