Autor Beitrag
theGrudge
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mi 13.12.06 12:59 
Hallo.

Folgendes Problem:
Ich möchte ein Programm machen, in welchem ein Benutzer durch klicken auf die Zeichenfläche (canvas) sich beliebig viele Punkte vorgeben kann die letztendlich zu einem Polygon verbunden werden.
Mir ist im Prinzip alles klar, aber mir fehlen die Kenntnisse, wie ich die procedure polygon verwende in Zusammenhang mit einem dynamischen array. Könnte mir das jemand verstänlich erklären (Die Delphi Hilfe bringt mich nicht weit).
Wie funktioniert ein dynamischer array?
espen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90
Erhaltene Danke: 1


D6 Prof./D7 Prof. MSSQL, MySQL
BeitragVerfasst: Mi 13.12.06 15:33 
Hallo,

hier mal gaaaaaanz knapp:

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:
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Polygon      : Array of TPoint;
    PolygonCount : Integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin

  inc(PolygonCount);
  Setlength(Polygon, PolygonCount);

  Polygon[PolygonCount - 1].X := X;
  Polygon[PolygonCount - 1].Y := Y;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PolygonCount := 0;
  Setlength(Polygon, PolygonCount);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  form1.Canvas.Polygon(Polygon);
end;