Autor Beitrag
JungerIslaender
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 427
Erhaltene Danke: 5

Win XP
Delphi 7; Delphi 2005
BeitragVerfasst: So 17.01.10 21:48 
Warumm bekomme ich bei folgendem Quellcode eine Exception der Klasse EAccessViolation:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
SetLength(Knoten_Array,Listbox1.Items.Count,8);
for i:= 0 to Listbox1.Items.Count do
  begin
  for j:= 0 to 7 do
    begin
    Knoten_Array[i,j]:=0;
    end;
  end;


Moderiert von user profile iconNarses: Titel erweitert.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 17.01.10 22:01 
Hi :)

Auch i müsste bis Length - 1 laufen, also greifst du für i = Listbox1.Items.Count auf Speicher außerhalb des Arrays zu. :zwinker:

mfG,

PS: Solche Fehler hat man, wenn man eigentlich ins Bett müsste =)
PS2: Der Titel gibt mehr Fragen als Antworten :)

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 17.01.10 22:04 
Weil du ein Array mit den Indizes 0..Listbox1.Items.Count - 1 erstellst, aber auf den Index Listbox1.Items.Count zugreifst wie user profile iconHidden schon geschrieben hat wie ich gerade sehe. Deshalb solltest du besser nicht zwei Sachen vermischen:
Wenn du auf das Array zugreifst, warum benutzt du dann für die Größenangabe andere Werte? Wenn du die Werte auch aus dem Array nimmst, kann so etwas nicht passieren... ;-)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  SetLength(KnotenArray, Listbox1.Items.Count, 8);
  for i := Low(KnotenArray) to High(KnotenArray) do
  begin
    for j := Low(KnotenArray[i]) to High(KnotenArray[i]) do
    begin
      KnotenArray[i, j] := 0;
    end;
  end;
JungerIslaender Threadstarter
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 427
Erhaltene Danke: 5

Win XP
Delphi 7; Delphi 2005
BeitragVerfasst: So 17.01.10 22:23 
user profile iconHidden hat folgendes geschrieben Zum zitierten Posting springen:
Hi :)
PS: Solche Fehler hat man, wenn man eigentlich ins Bett müsste =)


Jo das muss ich, hab als du es gesagt hast auch direkt den Fehler gesehen... :oops: :roll: