Autor Beitrag
bonanza
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Mi 23.11.05 20:05 
Sobald ich dies starte kommt ein fehler "access violiation" ... es liegt , so habe ich es ausgemacht in der markieren zeile...aber warum ? wie kann ich dieses problem beheben ?

danke schonmal im voraus

bonanza


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:
23:
24:
25:
26:
27:
28:
29:
procedure TForm1.Button1Click(Sender: TObject);

 var Zahlen: Array[1..100] of Boolean;
 var i, j, k: Integer;
 var offen: String;
begin
 for i:=1 to 100 do Zahlen[i]:=true;

 k:=0;
 while k <= 100  do
  begin
  k:= k +2;
  zahlen[k]:=false;
  end;

  for i:= 1 to 100 do
  begin
    if (zahlen[i+1]=true) then Zahlen[i+1]:=false;
    if (zahlen[i+1] = false) then Zahlen[i+1]:=true;  // <<--
  end;

 for j:= 1 to 100 do
 begin
  if Zahlen[j]=true
  then
    begin
      offen := offen + ',' + InttoStr(j);
      output.Text := offen;
    end;
ManuelGS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 173

Win XP HE, Suse Linux
D6, D7, D2005 Personal
BeitragVerfasst: Mi 23.11.05 20:15 
Dein Array geht von 1 bis 100
Du versuchst auf i+1 zuzugreifen, lässt dein Schleife aber von 1 bis 100 laufen. Zwangsweise wird auf Array-Index 101 zugegriffen, den es aber gar nicht gibt --> Access-Violation

_________________
"Leben ist gänzlich Bühne und Spiel; so lerne denn spielen
und entsage dem Ernst - oder erdulde das Leid." - Palladas von Alexandria
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 23.11.05 20:44 
was passiert denn im 100 Schleifendurchlauf (i=100)
genau: du versuchst das 101. Item zuzuweisen (i+1), dass es nicht gibt
warum überhaupt i+1, so wird das erste Item nie überprüft

edit: mist, zu langsam

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 23.11.05 22:26 
Du willst wahrscheinlich nicht + 1 sondern - 1 und dann musst du das Array mit 0 anfangen lassen ([0..99]).

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
bonanza Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Mi 23.11.05 22:52 
also ich wollte einmal jeden 2. Wert auf false setzen, jeden 3. wert tauschen also wer true ist soll false werden und umgekehrt...

und mit dem 4. das selbe also auch jeden wert tauschen....


was muss ich dafür wie ändern ?
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Mi 23.11.05 22:59 
schau dir mal das reservierte Wort mod an (F1)

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)