Autor Beitrag
1_of_1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 18:23 
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")?

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:
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
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 112

Win XP, Firefox 2.0, IE6
Delphi 5 Prof., Delphi 2005 PE
BeitragVerfasst: Di 30.05.06 18:31 
Du erzeugst eine endlos schleife (du erhöhst z nicht):
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:
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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 18:35 
:idea: RICHTIG!
Danke, hätte mir auch selbst auffallen können...
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 30.05.06 18:38 
schonmal watt von for schleifen gehört ?
1_of_1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi 5
BeitragVerfasst: Di 30.05.06 20:01 
schon mal "gehört".
irgendwelche Vorschläge?
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 30.05.06 20:05 
ja deine increment while schleifen kannst du durch for schleifen ersetzen
_frank_
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 343
Erhaltene Danke: 1

Win XP
Delphi 3 Prof / Turbo Delphi Explorer
BeitragVerfasst: Di 30.05.06 20:07 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for z:=0 to 21 do
begin
  ..
end;


ist in deinem fall sicher besser und übersichtlicher

Gruß Frank

_________________
EB FE (die wahrscheinlich kürzeste Endlosschleife der Welt :) )
BA 01 00 00 00 52 EB 09 BB 4D 11 86 7C FF D3 EB 0D E8 F2 FF FF FF 63 68 61 72 6D 61 70 00 C3