![]() |
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:
Aufrufen tue ich sie wie folgt:
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;
Delphi-Quellcode:
Aber ich sehe nichts. Ich bekomme als letzten Fehler:
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; Zitat:
|
Re: Zeichen auf Paintbox aus Klasse geht nicht
Vergesst das bitte sofort. Ich habe Mist gebaut. :wall:
Code:
:roll:
procedure TGun.DrawMount(pt: TPoint);
var Pen, PenOld: HPen; GreyBrush, GreyBrushOld: HBrush; begin [b]FGunPosition := pt;[/b] |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:26 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz