Entwickler-Ecke

Sonstiges (Delphi) - Wieso stürzt das Programm ab?


1_of_1 - Di 30.05.06 18:23
Titel: Wieso stürzt das Programm ab?
Hab ein Problem:
beim klicken auf den Radiobutton wird die folgende Prozedur initialisiert. Warum stürzt dabei das Programm ohne Fehlermeldung ab (bzw. "hängt sich auf")?


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:
procedure TForm1.RadioButton1Click(Sender: TObject);
var i, z, n:integer;
begin
z:=11;
while z<21 do
      begin
      if TRadioButton(FindComponent('RadioButton'+IntToStr(z))).Checked=true
         then begin
              i:=0;
              while i<100 do
                    begin
                    TLabel(FindComponent('Label'+IntToStr(i))).color:=NORMAL;
                    i:=i+1;
              end;
              i:=z-11;
              n:=0;
              if i=0
                 then begin
                      while n<10 do
                            begin
                            TLabel(FindComponent('Label'+IntToStr(n))).color:=AUSWAHL;
                            n:=n+1;
                      end;
                      end
                 else begin
                      while n<10 do
                            begin
                            TLabel(FindComponent('Label'+IntToStr(i)+IntToStr(n))).color:=AUSWAHL;
                            n:=n+1;
                            end;
                      end;
      end;
      end;

xKoordinateE.Text:='1';
RadioButton1.Checked:=True;
label0.color:=AUSWAHL;
z:=1;
while z<10 do
    begin
    TLabel(FindComponent('Label'+IntToStr(z)+'0')).color:=AUSWAHL;
    z:=z+1;
    end;
end;


DelphiAnfänger - Di 30.05.06 18:31
Titel: Re: Wieso stürzt das Programm ab?
Du erzeugst eine endlos schleife (du erhöhst z nicht):

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:
while z<21 do //solange z<21
 begin
 if TRadioButton(FindComponent('RadioButton'+IntToStr(z))).Checked=true then 
 begin
  i:=0;
  while i<100 do
  begin
   TLabel(FindComponent('Label'+IntToStr(i))).color:=NORMAL;
   i:=i+1;
  end;
  i:=z-11;
  n:=0;
  if i=0 then 
  begin
   while n<10 do
   begin
    TLabel(FindComponent('Label'+IntToStr(n))).color:=AUSWAHL;
    n:=n+1;
   end;
  end
  else 
  begin
   while n<10 do
   begin
    TLabel(FindComponent('Label'+IntToStr(i)+IntToStr(n))).color:=AUSWAHL;
    n:=n+1;
   end;
  end;
 end;
...


1_of_1 - Di 30.05.06 18:35

:idea: RICHTIG!
Danke, hätte mir auch selbst auffallen können...


F34r0fTh3D4rk - Di 30.05.06 18:38

schonmal watt von for schleifen gehört ?


1_of_1 - Di 30.05.06 20:01

schon mal "gehört".
irgendwelche Vorschläge?


F34r0fTh3D4rk - Di 30.05.06 20:05

ja deine increment while schleifen kannst du durch for schleifen ersetzen


_frank_ - Di 30.05.06 20:07


Delphi-Quelltext
1:
2:
3:
4:
for z:=0 to 21 do
begin
  ..
end;


ist in deinem fall sicher besser und übersichtlicher

Gruß Frank