Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Zeichen auf Paintbox aus Klasse geht nicht (https://www.delphipraxis.net/12298-zeichen-auf-paintbox-aus-klasse-geht-nicht.html)

Luckie 24. Nov 2003 17:59


Zeichen auf Paintbox aus Klasse geht nicht
 
Folgendes Ich habe mir eine Zeichenroutine gemacht. Was sie zeichnet ist egal, es werden nur GDI Zeichenfunktionen aufgerufen. Dies habe ich in eine Klasse gekapselt. Diese sieht wie folgt aus:
Delphi-Quellcode:
type
  TGun = class
  private
    FDC: HDC;
    FGunPosition: TPoint;
    FDegree: Cardinal;
    FGunEndPoints: TPoint;
    procedure GunEndPoints(Degree: Cardinal);
    procedure DrawMuzzle(Degree: Cardinal);
  public
    constructor Create(DC: HDC);
    property DC: HDC read FDC;
    procedure DrawMount(pt: TPoint);
    property Degree: Cardinal read FDegree write DrawMuzzle;
    property GunEndPoint: TPoint read FGunEndPoints;
  end;

implementation

constructor TGun.Create(DC: HDC);
begin
  FDC := DC;
end;

procedure TGun.DrawMount(pt: TPoint);
var
  Pen, PenOld: HPen;
  GreyBrush, GreyBrushOld: HBrush;
begin
  Pen := CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  PenOld := SelectObject(FDC, Pen);
  GreyBrush := CreateSolidBrush(RGB(240, 240, 240));
  GreyBrushOld := SelectObject(FDC, GreyBrush);
  Rectangle(FDC, FGunPosition.X, FGunPosition.Y, FGunPosition.X - 20,
    FGunPosition.Y - 7);
  Chord(FDC, FGunPosition.X - 1, FGunPosition.Y + 19, FGunPosition.X - 19,
    FGunPosition.Y - 14,
    FGunPosition.X - 4, FGunPosition.Y - 5, FGunPosition.X - 16, FGunPosition.Y
      - 5);
  SelectObject(FDC, GreyBrushOld);
  DeleteObject(GreyBrush);
  SelectObject(FDC, PenOld);
  DeleteObject(Pen);
end;

procedure TGun.GunEndPoints(Degree: Cardinal);
begin
  FGunEndPoints.X := Round(cos(Degree / 180 * Pi) * LENMUZZLE);
  FGunEndPoints.Y := Round(sin(Degree / 180 * Pi) * LENMUZZLE);
end;

procedure TGun.DrawMuzzle(Degree: Cardinal);
begin
  GunEndPoints(Degree);
  MoveToEx(FDC, FGunPosition.X-10, FGunPosition.Y-12, nil);
  LineTo(FDC, FGunPosition.X-10+FGunEndPoints.X, FGunPosition.Y-FGunEndPoints.Y-12);
end;
Aufrufen tue ich sie wie folgt:
Delphi-Quellcode:
procedure TForm1.btnStartClick(Sender: TObject);
var
  pt: TPoint;
  Gun: TGun;
begin
  Gun := TGun.Create(PaintBox1.Canvas.Handle);
  try
    pt.X := 106;
    pt.Y := PaintBox1.Height - 20;
    Gun.DrawMount(pt);
    Gun.Degree := 45;
  finally
    FreeAndNil(Gun);
  end;
end;
Aber ich sehe nichts. Ich bekomme als letzten Fehler:
Zitat:

Zitat von Der dumme blöde Debugger
'Ein Aufruf einer Betriebssystemfunktion ist fehlgeschlagen'.

Ich bin etwas rat los.

Luckie 24. Nov 2003 18:05

Re: Zeichen auf Paintbox aus Klasse geht nicht
 
Vergesst das bitte sofort. Ich habe Mist gebaut. :wall:

Code:
procedure TGun.DrawMount(pt: TPoint);
var
  Pen, PenOld: HPen;
  GreyBrush, GreyBrushOld: HBrush;
begin
  [b]FGunPosition := pt;[/b]
:roll:


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:35 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