Autor Beitrag
gamer94
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 41

Win7 HP, WinXP
Delphi 7 Pers.
BeitragVerfasst: Fr 10.10.08 23:06 
Ich habe folgenden Code:
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:
45:
land := TStringList.create;
region := TStringList.create;
typ := TStringList.create;
spec := TStringList.create;

land.LoadFromFile('li1cou.kvl');
region.LoadFromFile('li2reg.kvl');
typ.LoadFromFile('li3typ.kvl');
spec.LoadFromFile('li4spc.kvl');

panel1.Visible := false;
panel2.Visible := true;

for i := 0 to ListBox1.Items.Count -1 do
 begin
  if ListBox1.Selected[i] then
   sect := ListBox1.Items.Strings[i];
end;

label3.Caption := ini.ReadString(sect,'kombination','');
Label4.Caption := 'Kombination: ' + ini.readString(sect,'kombination','');
Label5.Caption := 'Land: ' + land.Strings[ini.ReadInteger(sect,'land',0)];
label6.Caption := 'Region: ' + region.Strings[ini.ReadInteger(sect,'region',0)];
label7.Caption := 'Typ: ' + typ.Strings[ini.ReadInteger(sect,'typ',0)];

case ini.ReadInteger(sect,'position',0of
  0: Label8.Caption := 'Position: Vorne';
  1: Label8.Caption := 'Position: Hinten';
end;

case ini.ReadInteger(sect,'auhu',0of
  0: Label9.Caption := 'HU/AU: Ja';
  1: Label9.Caption := 'HU/AU: Nein';
end;

label10.Caption := 'Speziell: ' + spec.Strings[ini.ReadInteger(sect,'spec',0)];

if ini.ReadBool(sect,'pic',false) = true then
image1.Picture.LoadFromFile('img\' + sect + '.' + ini.ReadString(sect,'picde','bmp'));


land.Free;
region.Free;
typ.Free;
spec.Free;


In meiner Listbox habe ich wunderschön alle Sections aufgelistet:

ausblenden Quelltext
1:
2:
3:
4:
5:
P94CU19
349IU73
H23D74N
4Z6UUIO
OP0ZTW3


Wenn ich nun einen Eintrag anklicke passiert folgendes:

ausblenden Quelltext
1:
2:
3:
4:
5:
P94CU19 < Alles richtig, Daten werden aus der INI ausgelesen
349IU73 < Auch hier kein Problem
H23D74N < "Listenindex überschreitet das Maximum (2)"
4Z6UUIO < "Listenindex überschreitet das Maximum (1)"
OP0ZTW3 < Alles wieder richtig


Ich versteh momentan nicht so ganz was da los ist. Freue mich über jede hilfe. :)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Fr 10.10.08 23:12 
Wo steht der gepostete Quelltext? Wird er beim Auswählen ausgeführt? Aber warum werden dann die Dateien immer neu eingelesen? :grubel:

Und wo genau tritt der Fehler denn auf? Wenn du uns eine Zeilennummer nennst, können wir dir besser helfen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 10.10.08 23:13 
Wie wäre es, wenn du deinen Code debuggst, also schrittweise den Code ausführst und einfach mal schaust was passiert und wo der Fehler auftritt? Wenn du dabei schaust welche Werte die Variablen annehmen, dann siehst du auch schnell wo der Fehler liegt.

Ohne jedenfalls den Inhalt deiner INI-Datei zu kennen kann niemand deinen Code nachvollziehen ;-).

Klar ist: Der Fehler tritt irgendwo auf, wo du auf eine Liste zugreifst. Dabei gibst du einen Index an, der nicht existiert. Also es sind zum Beispiel 2 Strings in der Liste und du greifst auf Index 2 zu, also den nicht existierenden dritten Eintrag. Ein Beispiel wäre hier:
ausblenden Delphi-Quelltext
1:
label10.Caption := 'Speziell: ' + spec.Strings[ini.ReadInteger(sect,'spec',0)];					
Aber ob die Zeile der Fehler ist oder welche andere es ist kann man nicht sagen, denn der benutzte Index wird ja hier zum Beispiel aus der unbekannten INI eingelesen.
gamer94 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 41

Win7 HP, WinXP
Delphi 7 Pers.
BeitragVerfasst: Sa 11.10.08 12:31 
ausblenden Delphi-Quelltext
1:
2:
3:
Label5.Caption := 'Land: ' + land.Strings[ini.ReadInteger(sect,'land',0)];
label6.Caption := 'Region: ' + region.Strings[ini.ReadInteger(sect,'region',0)];
label7.Caption := 'Typ: ' + typ.Strings[ini.ReadInteger(sect,'typ',0)];


In den drei Zeilen klemmt´s wohl, wenn ich die auskommentiere klappt alles.
Der Inhalt der INI sieht so aus:

ausblenden volle Höhe 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:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
[P94CU19]
kombination=P94CU19
auhu=1
position=0
land=0
region=0
typ=0
spec=0
pic=1
picde=bmp

[349IU73]
kombination=349IU73 
auhu=1
position=0
land=0
region=0
typ=0
spec=0
pic=1
picde=bmp

[H23D74N]
kombination=H23D74N
auhu=0
position=0
land=2
region=0
typ=1
spec=0
pic=0
picde=bmp

[4Z6UUIO]
kombination=4Z6UUIO
auhu=1
position=0
land=1
region=0
typ=1
spec=0
pic=0
picde=bmp

[OP0ZTW3]
kombination=OP0ZTW3
auhu=1
position=0
land=0
region=0
typ=0
spec=0
pic=0
picde=bmp


Wenn man übrigens noch eine Section in die INI schreibt geht´s wieder mit:
"Listenindex überschreitet das maximum (2)" weiter. Danach "Listenindex überschreitet das maximum (1)" der nächste Eintrag geht wieder und so weiter… Was hab ich da für ein verkorkstes Programm gebastelt? :D
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 11.10.08 12:37 
user profile icongamer94 hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
land.LoadFromFile('li1cou.kvl');					
user profile icongamer94 hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
Label5.Caption := 'Land: ' + land.Strings[ini.ReadInteger(sect,'land',0)];					
ausblenden Quelltext
1:
2:
3:
4:
5:
[H23D74N]
kombination=H23D74N
auhu=0
position=0
land=2
Was steht denn in der Datei li1cou.kvl in Zeile 3, auf die du ja zuzugreifen versuchst? Da damit der Index 2 das Maximum überschreitet gibt es wohl nur maximal 2 Zeilen in der Datei.
gamer94 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 41

Win7 HP, WinXP
Delphi 7 Pers.
BeitragVerfasst: Sa 11.10.08 12:46 
Es war nicht das INI-Lese Programm schuld, sondern das INI-Schreib Programm. Das hat die falschen Zahlen in die INI geschrieben. Zahlen für Zeilen die in meiner Stringliste nicht existieren. Ich könnte mir in den Hintern beißen. Man sowas peinliches, ich stelle irgendwie immer äußerst bescheuerte Fragen hab ich so das Gefühl.
Danke an alle, klappt jetzt. :oops: