Autor Beitrag
crackm
Hält's aus hier
Beiträge: 10



BeitragVerfasst: So 13.04.08 15:55 
Habe vor kurzem angefangen mit Delphi zu programmieren, d.h. kenn ich mich noch nicht gut aus d.h. würde ich einfache Erklärungen bevorzugen. Bei meinem jetzigem Projekt, wenn ich es versuche zu compilieren kommen folgende Fehlermeldungen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
[Hint] Unit1.pas(50): Value assigned to 'FirstPoly' never used
[Warning] Unit1.pas(49): Variable 'FirstPoly' might not have been initialized
[Error] Unit1.pas(88): This form of method call only allowed for class methods
[Error] Unit1.pas(89): Incompatible types: 'TEdit' and 'String'
[Error] Unit1.pas(90): Incompatible types: 'TEdit' and 'String'
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'


Der Scipt sieht folgender maßen 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:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
unit Unit1;

interface

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

type
TPoly=class(Tobject)
x:integer;
y:integer;
NextEdge:TPoly;
//Vor.: Keine
//Eff.:Fügt die Kordinaten einer weiteren Ecke des Polygons
procedure Add(x, y:integer);
//Vor.:Mindestens drei Kordinaten sind vorhanden.
//Eff.:Zeichent im aCanvas den Polygone
procedure Draw(Image1: TImage);
end;
TForm1 = class(TForm)
edx: TEdit;
edy: TEdit;
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
//-----------------------------------------------------------------------------
procedure TPoly.Add(x, y:integer);
var
aPoly:TPoly;
p:TPoly;
FirstPoly:TPoly;
begin
aPoly:=TPoly.Create;
aPoly.x:=x;
aPoly.y:=y;
if FirstPoly= nil then
FirstPoly:=aPoly
else begin
p:=FirstPoly;
while p.NextEdge <>NIL do p:= p.NextEdge;
p.NextEdge := aPoly;
end;
end;
//-----------------------------------------------------------------------------
procedure TPoly.Draw(Image1: TImage);
var
x, y:integer;
k:TPoly;
begin
Image1.Canvas.Pen.Color := clBlack;
with Image1 do begin
k:=Self;
x:=k.x;
y:=k.y;
Image1.Canvas.moveTo(x,y);
while k.NextEdge <> NIL do
begin
k:=k.NextEdge;
x:=k.x;
y:=k.y;
Image1.Canvas.lineTo(x,y);
end;
end;


end;
//------------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
x, y: Integer;

begin
x:=StrToInt(edx.Text);
y:=StrToInt(edy.Text);
TPoly.Add(x, y);
edx:='';
edy:='';
end;
//------------------------------------------------------------------------------
end.


Dazu habe ich zwei Frage zum einem, wie kann ich die Fehler behen und zum anderem wie kann ich zeichnen lassen?
Würde mich über eine schnelle Antwort sehr freuen.

Moderiert von user profile iconKlabautermann: Code- & Delphi-Tags hinzugefügt.
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 13.04.08 16:11 
Hast du dir schon die Fehlermeldungen angeguckt? TEdit <> string. Du schreibst: edx := '';. Du meinst aber wahrscheinlich: dex.Text := '';. TEdit bleibt TEdit und string bleibt string.

Du schreist in Draw: k := Self. Würde ich nicht machen! Sprich das Teil gleich mit Self an! Oder für Eigenschaften musst du es gar nicht angeben. Wie bei Form! Da brauchst du auch nicht Form1.Caption zu schreiben, sondern kannst Caption schreiben.

Du verwendest Image1 in TPoly. Darfst du nicht! Korrekt heißt es Form1.Image1. Du darfst nur Image1 schreiben, wenn die Prozedur / Funktion in TForm1 deklariert ist.

Und wenn du ein Polygon brauchst: Warum benutzt du kein dynamisches Array of TPoint, oder verwendest TCanvas.Polygon?
crackm Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: So 13.04.08 16:18 
Kannst du näher erläutern was ich schreiben sollte um TCanvas.Polygon zu benutzen?
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 13.04.08 16:26 
Erst einmal zu TPoint: Das verwendest du so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  mypoint: TPoint;
begin
  mypoint.X := 12;    // X-Position
  mypoint.Y := 5;     // Y-Position
end;


Dann schreibst du für das Benutzen von Polygon:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
var
  coordinates: array of TPoint;
begin
  SetLength(coordinates, 4);  // 5 Elemente (Indizierung beginnt bei 0)
  //-------------------------------------------------------------------
  coordinates[0].X := 10;
  coordinates[0].Y := 50;
  //-------------------------------------------------------------------
  coordinates[1].X := 50;
  coordinates[1].Y := 2;
  //-------------------------------------------------------------------
  coordinates[2].X := 80;
  coordinates[2].Y := 50;
  //-------------------------------------------------------------------
  coordinates[3].X := 50;
  coordinates[3].Y := 98;
  //-------------------------------------------------------------------
  coordinates[4].X := 10;
  coordinates[4].Y := 50;
  //-------------------------------------------------------------------
  Form1.Canvas.Polygon(coordinates);
end;


Guck sonst in der Hilfe unter TCanvas -> Methoden -> Polygon.
crackm Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: So 13.04.08 16:34 
Und was kann man mit [Error] Unit1.pas(88): This form of method call only allowed for class methods machen?
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: So 13.04.08 16:44 
Ich denke, dass Zeile 87 gemeint ist. Du schreibst: TPoly.Add ... Und das in TForm1! Das geht nicht. Du müsstest irgendwo eine Variable deklarieren und sowas hier in der Form verwenden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  MyPoly: TPoly;     //  <-----------|
begin                //              |
  ...                //              |
  MyPoly.Add(x, y);  //  ------------|
end;
crackm Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: So 13.04.08 16:50 
k, thx hab es jetzt