AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi uhr in delphi--> wie die zeiger?
Thema durchsuchen
Ansicht
Themen-Optionen

uhr in delphi--> wie die zeiger?

Ein Thema von XeRo · begonnen am 27. Mär 2004 · letzter Beitrag vom 24. Nov 2004
Antwort Antwort
Seite 2 von 3     12 3      
Benutzerbild von KingofWerlte
KingofWerlte

Registriert seit: 7. Feb 2004
Ort: Werlte
59 Beiträge
 
Delphi 6 Personal
 
#11

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 16:22
würde aber auch anders gehn ohne die procedur berechne_xy

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
VAR winkel: Real;
    x, y, x1, y1, r, i: Integer;
    hour, min, sec, msec: Word;

begin
Form1.Caption := DateTimeToStr(Now);

        (*alte Grafik löschen*) 
        Refresh;

        (*Einpssen des Kreises in das Fenster*) 
         if Width <= Height
                then r := Width div 3
                else r := Height div 3;


        (*Umwandlung in einzelne Integer-Werte*) 
        DecodeTime(Now, hour, min, sec, msec);

        (*Sekundenzeiger*) 
        winkel := sec * (((2 * pi) / 60)) - pi / 2;

        x := Trunc(Cos(winkel)* r);
        y := Trunc(Sin(winkel)* r);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);

        (*Minutenzeiger*) 
        winkel := min * (((2 * pi) / 60)) - pi / 2;

        x := Trunc(Cos(winkel)* r);
        y := Trunc(Sin(winkel)* r);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) - 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) - 1);
        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.61);
        y := Trunc(Sin(winkel)* r * 0.61);

        x := x + (Width div 2);
        y := y + (Height div 2);

        Canvas.Moveto(Width div 2, Height div 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 1, (Height div 2) - 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) + 1);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 1), (Height div 2) - 1);
        Canvas.LineTo(x , y);
        Canvas.Moveto((Width div 2) + 2, (Height div 2) + 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2) + 2, (Height div 2) - 2);
        Canvas.LineTo(x , y);
        Canvas.Moveto((Width div 2 - 2), (Height div 2) + 2);
        Canvas.LineTo(x, y);
        Canvas.Moveto((Width div 2 - 2), (Height div 2) - 2);
        Canvas.LineTo(x , y);

        (*Mittelpunkt*) 
        Canvas.Ellipse((Width div 2)-4, (Height div 2)-4,(Width div 2)+ 4,(Height div 2)+ 4);

        (*Ziffernstriche*) 
         i := 0;
         FOR i := 0 TO 11 DO
         begin
         winkel := i * (((2 * pi) / 12)) - pi / 2;

         x := Trunc(Cos(winkel)* 1.1*r);
         x1 := Trunc(Cos(winkel)* r);
         y := Trunc(Sin(winkel)* 1.1*r);
         y1 := Trunc(Sin(winkel)* r);

         x := x + (Width div 2);
         x1 := x1 + (Width div 2);
         y := y + (Height div 2);
         y1 := y1 + (Height div 2);
        Canvas.Moveto(x, y);
        Canvas.LineTo(x1, y1);
         end;

        (*Minutenpunkte*) 
         i := 0;
         FOR i := 0 TO 59 DO
         begin
         winkel := i * (((2 * pi) / 60)) - pi / 2;

         x := Trunc(Cos(winkel)* 1.1*r);
         y := Trunc(Sin(winkel)* 1.1*r);

         x := x + (Width div 2);
         y := y + (Height div 2);
          Canvas.Pixels[x, y] := clRed;
         Canvas.Ellipse(x-2, y-2,x+2,y+2);
         end;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := True;
end;

end.
1, 2 Billy kommt vorbei.. 3, 4 er steht vor deiner Firma.. 5, 6 gleich holt dich der Ruin.. 7, 8 es ist gleich aus für dich.. 9, 10 deine Firma gehört jetzt M$
  Mit Zitat antworten Zitat
Lillebrohr
(Gast)

n/a Beiträge
 
#12

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 16:28
Hi,

scrapt schrieb:

Zitat:
ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????
  Mit Zitat antworten Zitat
XeRo

Registriert seit: 23. Okt 2003
Ort: Warth
461 Beiträge
 
Delphi 7 Enterprise
 
#13

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 16:43
Zitat von Lillebrohr:
Hi,

scrapt schrieb:

Zitat:
ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????


so...nachdem ich jetzt genug wuelltext hab werd ich mal alle austesten und dann auch versuchen selbst einen zu schreiben...
  Mit Zitat antworten Zitat
sCrAPt
(Gast)

n/a Beiträge
 
#14

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 17:15
Zitat von Lillebrohr:
Hi,

scrapt schrieb:

Zitat:
ich kenn mein buch in und auswendig
AutorOfBook := scrapt; ????
1. Ich heiß Robert, nicht Thomas
2. Ab bisle zu jung um ein solches Buch rauszubringen
3. Ich beherrsche die Rechtschreibung genau so wenig wie meine Lampe...

^^ raise exception.create('''sCrAPt'' ist ein unzulässiger Autorname für das Buch');

@KingofWerlte: Meinet wegen kannste es auch in ASM schreiben

, sCrAPt
  Mit Zitat antworten Zitat
XeRo

Registriert seit: 23. Okt 2003
Ort: Warth
461 Beiträge
 
Delphi 7 Enterprise
 
#15

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 18:39
Ich will euch ja nicht zu nahe treten,aber wenn dass ein admin ließt, dann heißt es wieder: Offtopic
  Mit Zitat antworten Zitat
Benutzerbild von KingofWerlte
KingofWerlte

Registriert seit: 7. Feb 2004
Ort: Werlte
59 Beiträge
 
Delphi 6 Personal
 
#16

Re: uhr in delphi--> wie die zeiger?

  Alt 29. Mär 2004, 19:20
@sCrAPt rofl
1, 2 Billy kommt vorbei.. 3, 4 er steht vor deiner Firma.. 5, 6 gleich holt dich der Ruin.. 7, 8 es ist gleich aus für dich.. 9, 10 deine Firma gehört jetzt M$
  Mit Zitat antworten Zitat
Mr_Anderson

Registriert seit: 7. Okt 2004
Ort: Solingen
11 Beiträge
 
#17

Re: uhr in delphi--> wie die zeiger?

  Alt 23. Nov 2004, 16:37
Ich habe im internet auch noch einen Code für eine Klasse gefunden, jedoch sagt mit die klasse TRect nichts. Welchen Wert erwartet man wenn man eine Variable die Klasse TRect zuweist?

Anfgefügt habe ich den quellcode
//Edit:
Hab nun einen Tipp von einem "DPUser" erhalten
also dass ich einfach
Delphi-Quellcode:
kor.Top := 100;
kor.Left:= 200;
kor.Right:=100;
kor.Bottom:=100;
so eine TRect Variable aussehen kann, jedoch stürzt das Programm mit einer zugriffsverletzung ab:
test.Create(kor,Form1); MfG
Delphi-Quellcode:
uses Forms, {TForm}
     Windows,
     Messages,
     SysUtils,
     Variants,
     Classes,
     Controls,
     Dialogs,
     ExtCtrls,
     math,
     Graphics; {TCanvas, TColor}

type TClock = class (TObject)
  private
    FPicture: TPicture;
    FBrush,FPen : TColor;
    FBack,FClock,FImage: TImage;
    FTimer: TTimer;
    procedure Circle;
    procedure FOnTimer(Sender: TObject);
    procedure SetBrush(AValue: TColor);
    procedure SetPen(AValue: TColor);
    procedure SetPicture(AValue: TPicture);
  public
    constructor Create(const ARect: TRect; const AParent: TWinControl);
    destructor Destroy; override;
  published
    property BrushColor: TColor read FBrush write SetBrush;
    property PenColor: TColor read FPen write SetPen;
    property Picture: TPicture read FPicture write SetPicture;
  end; //TClock

implementation

constructor TClock.Create(const ARect: TRect; const AParent: TWinControl);
begin
  inherited Create;
  FPen := clBlack;
  FBrush := clWhite;
  FPicture := TPicture.Create;
  FBack := TImage.Create(AParent);
  FClock := TImage.Create(AParent);
  FImage := TImage.Create(AParent);
  with FBack do
  begin
    Parent := AParent;
    Left := ARect.Left;
    Top := ARect.Top;
    Width := ARect.Right - Left;
    if Width < 50 then
      Width := 50;
    Height := ARect.Bottom - Top;
    if Height < 50 then
      Height := 50;
  end;
  with FClock do
  begin
    Parent := AParent;
    Transparent := TRUE;
    Left := FBack.Left;
    Top := FBack.Top;
    Width := FBack.Width;
    Height := FBack.Height;
    Circle;
  end;
  with FImage do
  begin
    Transparent := TRUE;
    Parent := AParent;
    Left := FBack.Left;
    Top := FBack.Top;
    Width := FBack.Width;
    Height := FBack.Height;
    Canvas.Pen.Width := (Width + Height) div 100;
  end;
  FTimer := TTimer.Create(AParent);
  with FTimer do
  begin
    Interval := 1000;
    OnTimer := FOnTimer;
    Enabled := TRUE;
  end;
end; //TClock.Create

procedure TClock.Circle;
begin
  with FClock do
    with Canvas do
    begin
      Pen.Width := (Width + Height) div 100;
      Pen.Color := Parent.Brush.Color;
      Brush.Color := Parent.Brush.Color;
      Font.Style := Font.Style + [fsBold];
      Font.Size := (Width + Height) div 30;
      Font.Color := FPen;
      Rectangle(Rect(Left, Top, Left + Width, Top + Height));
      Pen.Color := FPen;
      if (FBack.Picture.Graphic = nil) or
        (FBack.Picture.Graphic.Empty) then
        Brush.Color := FBrush;
      Ellipse(Rect(Left, Top, Left + Width, Top + Height));
      TextOut((Width - TextWidth('12')) div 2, Pen.Width + 2, '12');
      TextOut((Width - TextWidth('6')) div 2, Height - TextHeight('6') - Pen.Width, '6');
      TextOut(Left + 2 + Pen.Width, (Height - TextHeight('9')) div 2, '9');
      TextOut(Width - TextWidth('3') - 2 - Pen.Width, (Height - TextHeight('3')) div 2, '3');
    end;
end; //TClock.Circle

procedure TClock.FOnTimer(Sender: TObject);
var
  Default: Integer;
  Hour,
  Min,
  Sec,
  MSec: Word;
begin
  DecodeTime(Now, Hour, Min, Sec, MSec);
  Sec := Sec * 6;
  Min := Min * 6;
  Hour := Hour * 30;
  with FImage do
  begin
    with Canvas do
    begin
      if FPen <> clWhite then
        CopyMode := cmWhiteness
      else
        CopyMode := cmBlackness;
      CopyRect(FImage.BoundsRect, Canvas, FImage.BoundsRect);
      Pen.Color := FPen;
      MoveTo(Width div 2, Height div 2);
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Sec)) * (Width div 2 - Width div 8)), Height div 2 + Trunc(Cos(DegToRad(Sec)) * - (Height div 2 - Height div 8)));
      MoveTo(Width div 2, Height div 2);
      Default := Pen.Width;
      Pen.Width := Pen.Width + 1;
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Min)) * (Width div 2 - Width div 8)), Height div 2 + Trunc(Cos(DegToRad(Min)) * - (Height div 2 - Height div 8)));
      MoveTo(Width div 2, Height div 2);
      Pen.Width := Pen.Width + 1;
      LineTo(Width div 2 + Trunc(Sin(DegToRad(Hour)) * (Width div 3)), Height div 2 + Trunc(Cos(DegToRad(Hour)) * - (Height div 3)));
      Pen.Width := Default;
    end;
  end;
end; //TClock.FOnTimer

procedure TClock.SetBrush(AValue: TColor);
begin
  if FBrush <> AValue then
  begin
    FBrush := AValue;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetBrush

procedure TClock.SetPen(AValue: TColor);
begin

  if FPen <> AValue then
  begin
    FPen := AValue;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetPen

procedure TClock.SetPicture(AValue: TPicture);
begin
  FPicture.Assign(AValue);
  with FBack do
  begin
    Width := FImage.Width;
    Height := FImage.Height;
    Picture.Assign(FPicture);
    Stretch := TRUE;
    Circle;
    FOnTimer(FTimer);
  end;
end; //TClock.SetPicture

destructor TClock.Destroy;
begin
  FImage.Free;
  FPicture.Free;
  FBack.Free;
  FClock.Free;
  FTimer.Free;
  inherited Destroy;
end; //TClock.Destroy
  Mit Zitat antworten Zitat
Benutzerbild von arbu man
arbu man

Registriert seit: 3. Nov 2004
Ort: Krefeld
1.108 Beiträge
 
Delphi 7 Professional
 
#18

Re: uhr in delphi--> wie die zeiger?

  Alt 23. Nov 2004, 17:14
Schau dir mal JEDI an da ist eine richtige Uhr.
Björn
>> http://bsnx.net <<
Virtual DP Stammtisch v1.0"iw" am 19.09.2007 - ich war dabei!
  Mit Zitat antworten Zitat
Hansa

Registriert seit: 9. Jun 2002
Ort: Saarland
7.554 Beiträge
 
Delphi 8 Professional
 
#19

Re: uhr in delphi--> wie die zeiger?

  Alt 23. Nov 2004, 17:50
Zitat von Mr_Anderson:
...jedoch sagt mit die klasse TRect nichts. Welchen Wert erwartet man wenn man eine Variable die Klasse TRect zuweist?
Also, ich will ja nichts sagen. 8) Aber es liegt auf der Hand, daß die Delphi-Hilfe das weiß. Und "Rect" sieht doch in etwa schon wie "Rechteck" aus, oder ? Selbst wenn man die Bedeutung vom engl. "rectangle" nicht weiß.
Gruß
Hansa
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#20

Re: uhr in delphi--> wie die zeiger?

  Alt 23. Nov 2004, 22:11
Moin!

1. TRect ist nur ein Record und keine Klasse (zumindest in der alten Delphi Version die ich benutze - und ich weiss, im BCB ist es eine struct mit Methoden).
2. Du kannst ein Rechteck anstatt einzelnd die Werte zu füllen das ganze unter Benutzung der Rect() Funktion in einer Zeile füllen:
  MyRect := Rect(0, 0, 10, 10); 3. Wenn du damit die Klasse anlegen wolltest (instanziieren), dann ist das der Fehler:
test.Create(kor,Form1); Versuchs mal lieber so:
 test := TClock.Create(kor, Form1); 4. Wenn du schon auf fremde Implementationen stehst, hier und hier noch zwei andere Komponenten.

MfG
Muetze1
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 3     12 3      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz