Delphi-PRAXiS
Seite 1 von 4  1 23     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi TStringList bringt mich zum VerZweiFeln (https://www.delphipraxis.net/120719-tstringlist-bringt-mich-zum-verzweifeln.html)

Spiderpig_GER_15 15. Sep 2008 20:12


TStringList bringt mich zum VerZweiFeln
 
Hi,

Was ist im Gange das ich zu einer gaaanz normalen StringList nichts mehr adden kann?
Delphi-Quellcode:
    .
    .
    .
    end;
    Frame_1.SVoksToDo.Add('buhu');
    begin
    .
    .
    .
Die Zeilen obendrüber funktioniert es, nur DA wo ich es mometan brauche kommt immer ein ARRRRGH Error:

---------------------------
Debugger Exception Notification
---------------------------
Project Frame1.exe raised exception class EStringListError with message 'List index out of bounds (-1)'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

ich bin am Boden zerstört, ein out of bounds Error bei .Add???

Bitte, bittäää helft mir

MfG

Spiderpig

mkinzler 15. Sep 2008 20:14

Re: TStringList bringt mich zum VerZweiFeln
 
Bist du sicher, das der Fehler von diesem Befehl erzeugt wird?

Spiderpig_GER_15 15. Sep 2008 20:15

Re: TStringList bringt mich zum VerZweiFeln
 
ja, leider :(

lösche ich die Zeile funktioniert alles (bzw. es scheint so)

mkinzler 15. Sep 2008 20:21

Re: TStringList bringt mich zum VerZweiFeln
 
Zeig mal den kompletten Codeblock

Spiderpig_GER_15 15. Sep 2008 20:22

Re: TStringList bringt mich zum VerZweiFeln
 
ergänzung:
Delphi-Quellcode:
    .
    .
    .
    begin
      if StrList.Count >= 2 then
      begin
        iI:=random(StrList.Count);
        Frame_1.SVoksToDo.Add(StrList[iI]);
        repeat
          kI:=random(StrList.Count);
          Frame_1.SVoksToDo.Add('es geht'); //hier kein Prob
        until kI <> iI;
        Frame_1.SVoksToDo.Add(StrList[kI]);
      end;
    end;
    StrList.Clear;
  end;

  Frame_1.SVoksToDo.Add('es geht'); //hier error
  .
  .
  .
PS: reicht das, das komplett ist nämlich seehr lang

SirTwist 15. Sep 2008 20:24

Re: TStringList bringt mich zum VerZweiFeln
 
Zu welcher Routine bzw. Methode gehört dein Add-Befehl, der da fehlschlägt? Wann wird der Befehl ausgeführt und in welchem Zusammenhang? Bist Du sicher, dass die Stringlist an dieser Stelle überhaupt initialisiert ist?

Gruß,
SirTwist

mkinzler 15. Sep 2008 20:25

Re: TStringList bringt mich zum VerZweiFeln
 
Ist aller Code in der selben Methode?

Spiderpig_GER_15 15. Sep 2008 20:26

Re: TStringList bringt mich zum VerZweiFeln
 
da das vermutlich auch nciht weiter hilft, hier die ganze Unit:
Delphi-Quellcode:
unit MainCalcPart;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

  procedure VokCalc;

implementation

uses Frame;

procedure VokCalc;
var StrList: TStringList;
    iI, kI, lI, jI: Integer;
begin
  StrList:= TStringList.Create;
  Frame_1.SVoksToDo.Clear;
  StrList.Clear;

  randomize;

  //3 Neue Vokabeln
  begin
    for iI := 1 to 3 do
    begin
      If (Frame_1.LastVokIndex+1) <= Frame_1.OverAllVok then
      begin
        inc(Frame_1.LastVokIndex);
        Frame_1.SVoksToDo.Add(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(Frame_1.LastVokIndex))+7]);
      end;
    end;
  end;

  //5 aus Aktueller Lektion
  begin
    for iI := 1 to Frame_1.OverAllVok do
    begin
      If (strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)]) = Frame_1.acuteLekt) then
      begin
        If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
        begin
          if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
          begin
            StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
          end;
        end;
      end;
    end;
    begin
      if StrList.Count >= 5 then
      begin
        Frame_1.SVoksToDo.Add(StrList[random((StrList.Count-1) div 5)]);
        Frame_1.SVoksToDo.Add(StrList[random((StrList.Count-1) div 5)+ (1*((StrList.Count) div 5))]);
        Frame_1.SVoksToDo.Add(StrList[random((StrList.Count-1) div 5)+ (2*((StrList.Count) div 5))]);
        Frame_1.SVoksToDo.Add(StrList[random((StrList.Count-1) div 5)+ (3*((StrList.Count) div 5))]);
        Frame_1.SVoksToDo.Add(StrList[random(((StrList.Count-1) div 5) + ((StrList.Count) mod 5)) + (4*((StrList.Count) div 5))]);
        StrList.Clear;
      end;
    end;
  end;

  //2 Problemfälle aus akt. Lektion
  begin
    for Ii := 1 to Frame_1.OverallVok do
    begin
      If (strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)]) = Frame_1.acuteLekt) then
      begin
        If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
        begin
          if Frame_1.savestring[Frame_1.savestring.IndexOf('Nr' + inttostr(iI)) + 1] = '1' then
          begin
            if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
            begin
              if ((strtofloat(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(iI)) + 2])) /
                   (strtofloat(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(iI)) + 3]))) <
                     Frame_1.FailRatio then
              begin
                StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
              end;
            end;
          end;
        end;
      end;
    end;
    begin
      if StrList.Count >= 2 then
      begin
        iI:=random(StrList.Count);
        Frame_1.SVoksToDo.Add(StrList[iI]);
        repeat
          kI:=random(StrList.Count);
          Frame_1.SVoksToDo.Add('es geht');
        until kI <> iI;
        Frame_1.SVoksToDo.Add(StrList[kI]);
      end;
    end;
    StrList.Clear;
  end;


  //3 Problemfälle aus letzten beiden Lektionen
  begin
    for iI := 1 to Frame_1.OverAllVok do
    begin
      If ((strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)])) >= Frame_1.acuteLekt -2) and
              ((strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)])) < Frame_1.acuteLekt) then
      begin
        If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
        begin
          if Frame_1.savestring[Frame_1.savestring.IndexOf('Nr' + inttostr(iI)) + 1] = '1' then
          begin
            if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
            begin
              if ((strtofloat(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(iI)) + 2])) /
                   (strtofloat(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(iI)) + 3]))) <
                     (Frame_1.FailRatio - 0.2) then
              begin
                StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
              end;
            end;
          end;
        end;
      end;
    end;
    begin
      if StrList.Count >= 3 then
      begin
        iI:=random(StrList.Count);
        Frame_1.SVoksToDo.Add(StrList[iI]);
        repeat
          kI:=random(StrList.Count);
        until kI <> iI;
        Frame_1.SVoksToDo.Add(StrList[kI]);
        repeat
          lI:=random(StrList.Count);
        until (lI <> iI) and (lI <> kI);
        Frame_1.SVoksToDo.Add(StrList[lI]);
      end;
    end;
    StrList.Clear;
  end;

  //2 Zufall
  begin
    for iI := 1 to Frame_1.OverAllVok do
    begin
      If ((strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)])) < Frame_1.acuteLekt) then
      begin
        If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
        begin
          if Frame_1.savestring[Frame_1.savestring.IndexOf('Nr' + inttostr(iI)) + 1] = '1' then
          begin
            if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
            begin
              StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
            end;
          end;
        end;
      end;
    end;
    begin
      if StrList.Count >= 2 then
      begin
        iI:=random(StrList.Count);
        Frame_1.SVoksToDo.Add(StrList[iI]);
        repeat
          kI:=random(StrList.Count);
        until kI <> iI;
        Frame_1.SVoksToDo.Add(StrList[kI]);
      end;
    end;
    StrList.Clear;
  end;


  // Auffüllen etwaiger Lücken
  if Frame_1.SVoksToDo.Count < 15 then
  begin
    // 2 Zufall
    begin
      for iI := 1 to Frame_1.OverAllVok do
      begin
        If ((strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)])) < Frame_1.acuteLekt) then
        begin
          If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
          begin
            if Frame_1.savestring[Frame_1.savestring.IndexOf('Nr' + inttostr(iI)) + 1] = '1' then
            begin
              if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
              begin
                StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
              end;
            end;
          end;
        end;
      end;
      begin
        if StrList.Count > 0 then
        begin
          if Frame_1.SVoksToDO.Count = 1 then
          begin
            Frame_1.SVoksToDo.Add(StrList[random(StrList.Count)]);
          end
          else
          begin
            iI:=random(StrList.Count);
            Frame_1.SVoksToDo.Add(StrList[iI-1]);
            repeat
              kI:=random(StrList.Count);
            until kI <> iI;
            Frame_1.SVoksToDo.Add(StrList[kI-1]);
          end;
        end;
        begin
          iI:=15-Frame_1.SVoksToDo.Count;
          if iI >= 1 then
          begin
            begin
              for jI := 1 to iI do
              begin
                If not (Frame_1.LastVokIndex > Frame_1.OverAllVok) then
                begin
                  inc(Frame_1.LastVokIndex);
                  If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(Frame_1.LastVokIndex))+7]) = (-1) then
                  begin
                    Frame_1.SVoksToDo.Add(Frame_1.savestring[Frame_1.savestring.IndexOf('NR' + inttostr(Frame_1.LastVokIndex))+7]);
                  end
                  else
                  begin
                    break;
                  end;
                end
                else
                begin
                  break;
                end;
              end;
              If (Frame_1.LastVokIndex > Frame_1.OverAllVok) then
              begin
                //Zufälllig
                begin
                  for iI := 1 to Frame_1.OverAllVok do
                  begin
                    If ((strtoint(Frame_1.savestring[(Frame_1.savestring.IndexOf('NR'+ inttostr(iI)) + 5)])) < Frame_1.acuteLekt) then
                    begin
                      If Frame_1.SVoksToDo.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
                      begin
                        if Frame_1.savestring[Frame_1.savestring.IndexOf('Nr' + inttostr(iI)) + 1] = '1' then
                        begin
                          if StrList.IndexOf(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]) = (-1) then
                          begin
                            StrList.Add(Frame_1.savestring[Frame_1.savestring.indexOf('NR' + inttostr(iI))+7]);
                          end;
                        end;
                      end;
                    end;
                  end;
                  begin
                    for kI:=1 to (15 - Frame_1.SVoksToDo.count) do
                    begin

                        lI:= random(StrList.Count)+1;

                        //darum geht's: mache ich die Kommentarzeichen weg, ensteht der error!
                        //  Frame_1.SVoksToDo.Add('buhuuu');
                       
                    end;
                  end;
                  StrList.Clear;
                end;
              end;
            end;
          end;
        end;
      end;
    end;
    StrList.Clear;
  end;
end;
end.
um wenigstens etwas helfen zu können: Es geht um einen Vokabeltrainer, Das ganze ist dafür da um die "Abzufragenden" Vokabeln zusammen zu stellen.

MfG

Spiderpig

mkinzler 15. Sep 2008 20:27

Re: TStringList bringt mich zum VerZweiFeln
 
Bereinige mal den Code von den ganzen überflüssigen Begin und Ends

Spiderpig_GER_15 15. Sep 2008 20:29

Re: TStringList bringt mich zum VerZweiFeln
 
das schlimme ist, obendrüber Adde ich ja noch ganz viele andere Sachen, da funkt alles

Edit: Die begin/ends sind nicht überflüssig, ich lasse sie lieber da, hab schon zu oft den Fehler gemacht eine If-Anweisung zu schreiben ohne begin/end und es wurde nur die erste Zeile ausgeführt, statt alles was ich eigentlich wollte... So kann ich den Fehler nicht so leicht machen...


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:49 Uhr.
Seite 1 von 4  1 23     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz