Autor Beitrag
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Di 16.10.07 14:57 
Ich habe eine TStringList und fülle diese per For-Schleife. Leider erhalte ich beim Füllen die Meldung Listenindex überschreitet das Maximum. Mir kommt das sehr bekannt vor, aber die Google-Suche lässt mich auf keine Lösung stoßen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
...
if RecordCount > 0 then begin
 FOrginalKatalogEintraege := TStringList.Create;
  for k:=0 to RecordCount-1 do begin
   FOrginalKatalogEintraege[k] := (FieldByName('HGR_NR').AsString + ';' + FieldByName('UGR_NR').AsString); //Hier passiert der Fehler
   next;
  end;
end;
...

_________________
Das Unsympathische an den Computern ist, dass sie nur ja oder nein sagen können, aber nicht vielleicht.
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Di 16.10.07 14:58 
Hallo, k hat ja noch keinen Eintrag, versuchs mal mit FOrginalKatalogEintraege.add()
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Di 16.10.07 15:03 
Geht, find es aber unlogisch. k ergibt sich doch aus 0?

_________________
Das Unsympathische an den Computern ist, dass sie nur ja oder nein sagen können, aber nicht vielleicht.
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Di 16.10.07 15:05 
Woher kommt denn dein RecordCount?

Du durchläufst eine leere Liste (FOrginalKatalogEintraege) mit einem unbestimmten Max Record Count der nicht zu dieser Liste gehört. Du solltest vorher die Liste füllen und dann sagen:
ausblenden Delphi-Quelltext
1:
RecordCount := FOrginalKatalogEintraege.RecordCount;					


Die vorige Prüfung auf RecordCount -1 bringt überhaupt nichts, da selbst wenn die Liste keine Einträge hat die Schleife sofort abbricht.

Edit:
Sollte es nicht so heissen:
ausblenden Delphi-Quelltext
1:
FOrginalKatalogEintraege.Add((FieldByName('HGR_NR').AsString + ';' + FieldByName('UGR_NR').AsString));					

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.


Zuletzt bearbeitet von Alpha_Wolf am Di 16.10.07 15:10, insgesamt 3-mal bearbeitet
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Di 16.10.07 15:06 
ja, aber der nullte Eintrag ist ja nicht da, weil die Liste noch leer ist. Und da nimmt man erstmal Add() zum Füllen.