Autor Beitrag
Coder
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1383
Erhaltene Danke: 1

WinXP
D2005 PE
BeitragVerfasst: So 16.10.05 00:08 
Hi
Ich male per Canvas flächen auf mein Formular.
ausblenden Delphi-Quelltext
1:
  PaintBox1.Canvas.Polyline([Point(14,47), Point(14,485), Point(14,48)]);					

Nun möchte ich gerne die TPoint-Koordinaten in ein Array of TPoint "auslagern".
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var  Coords: Array [1..3] of TPoint;

[...]

  Coords := [Point(14,47), Point(14,485), Point(14,48)];

Jedoch gibt er mir auf der Markierten Positon den Fehler:
[Fehler] Unit1.pas(37): E2001 Ordinaltyp erforderlich

Wie könnte man das Problem lösen?
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: So 16.10.05 00:30 
du sprichst ja ein array so an: z.b. array[1]=2;
du kannst jedem array nur einen wert zuordnen. und jede variable des array bekommt einen index.
was mir jetzt einfällt wäre nen array von nem record.
z.b.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
tmeinrecord = record
 point:array [1..3] of tpoint;

var coords : array[1..3] of tmeinrecord;

...

coords[1].point[1].x:=14;
etc.

geht sicher noch kürzer und besser aber ich denk ma nen record is die richtige richtung...

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 16.10.05 09:04 
Hallo,

ein Record ist nicht erforderlich,
so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var  Coords: Array [1..3] of TPoint;
begin
  Coords[1].x := 20 ; Coords[1].y := 100;
  Coords[2].x := 200; Coords[2].y := 200;
  Coords[3].x := 100; Coords[3].y := 100;
  Canvas.Polygon(Coords);

oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  Coords[1] := Point(20,100);
  Coords[2] := Point(200,200);
  Coords[3] := Point(100,100);
  Canvas.Polygon(Coords);

Bei der Verwendung von Konstanten:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Const Coords2 : Array [1..3] of TPoint =
                             ((x:20; y:100),
                              (x:200; y:200),
                              (x:100; y:100));
begin
  Canvas.Polygon(Coords2);

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 16.10.05 09:14 
Eine Kleinigkeit noch:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Type
  T3PointArray = Array [1..3] of TPoint; 
Const Coords2 :  T3PointArray =
                             ((x:20; y:100),
                              (x:200; y:200),
                              (x:100; y:100));
Var
  a : T3PointArray;

Begin
  a := Coords2;
End;

geht auch noch (weil ein Vorposter meinte, man könne einem Array keinen Wert zuweisen).

_________________
Na denn, dann. Bis dann, denn.
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: So 16.10.05 13:40 
wow ok also kann man einem array einfach so werte zuweisen?:
ausblenden Delphi-Quelltext
1:
2:
3:
var d:=array[1..3] of integer;

d:=(1,3,5);

und dann is d[1]=1, d[2]=3 und d[3]=5?

ja ich weis eigentlich sollte ich nen neuen thread aufmachen aber macht mal bitte ne ausnahme liebe admins...

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 16.10.05 13:44 
Probiers aus.

_________________
Na denn, dann. Bis dann, denn.
Amateur
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 777

(Win98, WinMe) WinXP Prof
D3 Prof, D6 Pers, D2k5 Pers., Turbo C++ Explorer
BeitragVerfasst: So 16.10.05 13:57 
ok also ne direkte zuweisung ist nicht möglich aber wenn man es bei der variablen deklaration macht geht es...
in ner prozedur muss man also immer mit einer for schleife die werte zuweisen???
schade...
und nem point kann man über point(x,y) werte zuweisen. alles klar....

_________________
"Kein dummes Gerede. Kein Rumrätseln. Denkt an nichts anderes mehr, nur noch an das, was vor euch liegt. Das ist die wahre Herausforderung. Ihr müßt euch vor euch selbst schützen, Leute." (Rennes in "Cube")
Beiträge: >700