Einzelnen Beitrag anzeigen

Mr_Anderson

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

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

  Alt 23. Nov 2004, 17: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