Thema: Delphi Problem mit for-do

Einzelnen Beitrag anzeigen

fishbrain

Registriert seit: 17. Sep 2007
Ort: Regensburg
132 Beiträge
 
#1

Problem mit for-do

  Alt 25. Mär 2008, 22:46
Hi,

ich schreibe gerade eine Simulation des radioaktiven Zerfalls.
Ich baue dazu ein 2d Netz von Atomen auf und benuzte dazu for-do.

Delphi-Quellcode:
...
  for I := 0 to 29 do
   begin
    for k := 0 to 26 do
     begin
       atoms[i,k] := TAtom.create;
       atoms[i,k].x := I*35;
       atoms[i,k].y := K*35;
       atoms[i,k].changeatom(strtoint(edit1.text),strtoint(edit2.text));
       with canvas do
       begin
         brush.Color := atoms[i,k].color;
         ellipse(atoms[i,k].x,atoms[i,k].y,atoms[i,k].x+35,atoms[i,k].y + 35);
       end;
     end;
   end;
...
  for i := 0 to 29 do
    begin
      for k := 0 to 26 do
       begin
       if atoms[i,k].Knownnuklid = true then
       begin
        if atoms[i,k].stable = false then
        begin
          atoms[i,k].randomdecay(0.2);
          if atoms[i,k].stable = true then stable := stable +1;
        end;
       end;
      end;
...
 for I := 0 to 29 do
   begin
    for k := 0 to 26 do
     begin
       with canvas do
       begin
         brush.Color := atoms[i,k].color;
         font.Color := atoms[i,k].Fcolor;
         pen.Color := RGB(255,255,255);
         ellipse(atoms[i,k].x,atoms[i,k].y,atoms[i,k].x+35,atoms[i,k].y + 35);
         Font.Size := 8;
         Textout(atoms[i,k].x+15,atoms[i,k].y+10,atoms[i,k].Kuerzel);
         Font.Size := 6;
         Textout(atoms[i,k].x+4,atoms[i,k].y+5,inttostr(atoms[i,k].Protonen+atoms[i,k].Neutronen));
         Textout(atoms[i,k].x+4,atoms[i,k].y+16,inttostr(atoms[i,k].Protonen));
       end;
     end;
   end;
...
Soweit sogut. Hat auch bisher alles geklappt. Heute hab ich dann ein Diagramm auf einer weiteren Form mit eingebaut.

Delphi-Quellcode:
Procedure TForm1.paintchart;
var
 i:Integer;
begin
  with canvas do
  begin
    moveto(20,480);
    for I := 0 to np do
    begin
      lineto(ChartPoint[i].X+20,480-ChartPoint[i].y div 2);
    end;

  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  with canvas do
  begin
    Brush.Color := rgb(255,255,255);
    Rectangle(0, 0, 500, 500);
    MoveTo(20,480);
    LineTo(20,20);
    MoveTo(20,480);
    LineTo(480,480);
    textout(10,10,'Anzahl Teilchen');
    textout(450,480,'Zeit in s');
    paintchart;
  end;
end;

Procedure TForm1.addPoint;
begin
  Chartpoint[np].X := n;
  Chartpoint[np].Y := stable;
  np := np +1;
  n := n+1;
end;
Und seitdem hängt er sich manchmal(hab noch nicht herausgefunden wann) bei Zeile
if atoms[i,k].Knownnuklid = true then auf. Wenn ich dann über i bzw k mit dem mauszeiger gehe Zeigt er für i 30 und für k 17 an.
Aber eigentlich sollte es doch nur bis 29 und 26 gehen.oder?

Ich hab keine Ahnnung wie das zustande kommt, da es ja vorher ohne Probleme gegangen ist und ich nichts an der besagten Fehlerzeile geändert habe.

Würde mich sehr freuen wenn jemand eine Lösung parat hat( ).

MFG
  Mit Zitat antworten Zitat