Autor Beitrag
speck12
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mi 11.02.09 16:26 
Hallo allerseits,
ich hab ein Problem, und zwar kommt bei mir immer eine Zugriffsverletzung, wenn ich ein Array befüllen möchte.
Hier mal der Code, wo 'befüllt' wird:

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:
procedure TSpielfeld.Init(color : TColor);
 var m,n,o,p : Integer;
  begin
   BackgroundColor := color;

   with Hintergrund do
    begin
     Canvas.Pen.Color   := BackgroundColor;
     Canvas.Brush.Color := BackgroundColor;
     Canvas.Rectangle(0,0,width,height);
    end;
   Temp.Canvas.Draw(0,0,Hintergrund);

    {Koordinatensystem des Spielfeldes begrenzen und befüllen}
    m := (self.Width   DIV 20) -1;
    n := (self.Height  DIV 20) -1;
    SetLength(Struktur,m,n);
    for o := 0 to m do
     for p := 0 to n do
       begin
        Struktur[o,p].X := 0;
        Struktur[o,p].Y := 0;
       end;

  end;

  procedure TSpielfeld.SetSize(Size: TPoint);
   begin
    self.Width  := Size.X;
    self.Height := Size.Y;

    Temp.Width  := Size.X;
    Temp.Height := Size.Y;

    Hintergrund.Width  := Size.X;
    Hintergrund.Height := Size.Y;
   end;


 function TSpielfeld.CorrectMapSize(Mapsize: TPoint) : TPoint;
 var
  temp : TPoint;
  begin
   temp := Mapsize;
   if temp.X > 1280 then temp.X := 1280;
   if temp.Y > 800  then temp.Y := 800 ;
   if (temp.X MOD 20) <> 0 then temp.X := temp.X - ((temp.X MOD 20) * 20);
   if (temp.Y MOD 20) <> 0 then temp.Y := temp.Y - ((temp.Y MOD 20) * 20);

   result := temp;
  end;


bevor Init aufgrufen wird, werden CorrectMapSize und SetSize ausgeführt.
Zur Übersicht hab ich den Rest mal weggelassen, falls notwendig kann ich auch gerne den ganzen Quelltext posten.
Evtl sieht ja jemand den Fehler.
Danke schon mal
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 11.02.09 16:30 
Dein Array ist eine Stelle zu klein, oder?

SetLength(Struktur,m+1,n+1);

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
speck12 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36



BeitragVerfasst: Mi 11.02.09 16:33 
ohjeee, natürlich :D
Danke, jetzt läufts.