Autor Beitrag
ghayatan
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Di 01.02.05 08:43 
Hallo an alle,
ich versuche ein Dreieck auf einem Formular darzustellen. Allerdings nicht einfach als Polygon, sondern ich habe eine Unit dreieck und rufe sie dann im Hauptprogramm auf, das Programm läuft, aber es zeichnet mir nichts. Ich hoffe Ihr könnt mir helfen.
Hier der Code:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
unit Unit2;

interface
uses Graphics, Forms, Types;



type TDreieck = class(TObject)

private

public

constructor erzeugen(u,v,w,x,y,z : Integer; f : TForm);
procedure zeichnen;

end;

implementation

var
  z1: integer;
  Punkt : array[1..3] OF TPoint;
  cvs : TCanvas;

constructor TDreieck.erzeugen;
begin
  z1:= 0;
  f.Color := clWhite;
  Punkt[1].X := u;
  Punkt[1].Y := v;
  Punkt[2].X := w;
  Punkt[2].Y := x;
  Punkt[3].X := y;
  Punkt[3].Y := z;
  cvs := f.Canvas;
  cvs.Brush.Style := bsClear;
  cvs.Pen.Mode := pmXOR;
  zeichnen;
end;

procedure TDreieck.zeichnen;
begin
  with cvs do
    begin
      Brush.Color := clBlack;
      Pen.Color := clBlack;
      Polygon([Point(Punkt[1].X,Punkt[1].Y),Point(Punkt[2].X,Punkt[2].Y),Point(Punkt[3].X,Punkt[3].Y)]);
    end;
  end;
end.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;
var
 Dreieck1 : TDreieck;
{$R *.dfm}



procedure TForm1.FormCreate(Sender: TObject);
begin
 Dreieck1 :=  TDreieck.erzeugen(10,10,100,200,300,150,form1);
 Dreieck1.zeichnen;
end;

end.


Ich sag schon mal vielen Dank auch wenn vieleicht keiner mir helfen kann.

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.
st-matze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 138

Win 3.11, Win 95, Win 98, Win XP
D7 Ent, D6 Pers, (D5 Pers)
BeitragVerfasst: Di 01.02.05 09:38 
weiss XOR schwarz = weiss

ergo Friesische Nationalflagge:

WeisserAdler auf weissem Grund

//Edit:
entweder läßt du das XOR weg oder du entscheidest dich für Farbkombinationen, die sich nicht gegenseitick aufheben.
st-matze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 138

Win 3.11, Win 95, Win 98, Win XP
D7 Ent, D6 Pers, (D5 Pers)
BeitragVerfasst: Di 01.02.05 10:21 
probier mal aus

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
unit Unit2; 

interface
uses
  Graphics,
  Forms,
  Types;

type
  TDreieck = class(TObject)
  private
    bgC : TColor;// Hintergrundfarbe
    fgC : TColor;// Zeichenfarbe
    cvs : TCanvas;
    Punkt : array[1..3] OF TPoint;
    procedure Init;
  public
    constructor erzeugen(u,v,w,x,y,z : Integer; f : TForm);
    procedure zeichnen;
  end;

implementation
//Anstatt global in der Unit, in der Classe als private deklariert
//Ansonsten kannst du deine dreiecke nur übereinander malen.
//var
//z1: integer;
//  Punkt : array[1..3] OF TPoint;
//  cvs : TCanvas;

procedure TDreieck.Init;
begin
  bgC :=  clblack;
  fgC  :=  clwhite;
end;

constructor TDreieck.erzeugen;
begin
  Init;
//  z1:= 0;
  f.Color := bgC;
  Punkt[1].X := u;
  Punkt[1].Y := v;
  Punkt[2].X := w;
  Punkt[2].Y := x;
  Punkt[3].X := y;
  Punkt[3].Y := z;
  cvs := f.Canvas;
  cvs.Brush.Style := bsClear;
  //cvs.Pen.Mode := pmXOR;
  zeichnen;
end;

procedure TDreieck.zeichnen;
var c, fg,bg: longint;
begin
//kleine Funktionalität zum weichzeichen des Randes
//dann sieht dein dreieck nicht wie ein Zahnspachtel aus ;)
//für XOr Zeichen modus muss diese Funktionalität entsprechend angepasst werden
//funktioniert nur im normalen zeichen modus
  bg:=ColortoRGB(bgC);
  fg:=ColortoRGB(fgC);
  c :=ColortoRGB(fg);
  c := ((c mod 256) + (bg mod 256)) div 2 + //r anteil
        256 *(
       (((c div 256) mod 256) + ((bg div 256) mod 256) div 2) + //g anteil
        256 * (
        ((c div 65536) +(bg div 65536)) div 2));//b Anteil
  with cvs do
  begin
    Brush.Color := fg;
    Pen.Color   := c;
    Polygon([Point(Punkt[1].X,Punkt[1].Y),Point(Punkt[2].X,Punkt[2].Y),Point(Punkt[3].X,Punkt[3].Y)]);
  end;
end;

end.
ghayatan Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Di 01.02.05 12:20 
Vielen vielen dank es funktioniert.