Autor Beitrag
mara_buh
Hält's aus hier
Beiträge: 8


Delphi 6
BeitragVerfasst: Di 30.05.06 20:08 
Hi Leute...
ich hab ein kleines Problem. immer wenn ich versuche das Programm zu starten,
kommt eine gewisse Fehlermeldung und zwar: 'Listenindex überschreitet Maximum (0)'..
kann mir bitte jemand sagen, was da falsch ist???

Vielen dank schon im voraus!
lg mara-buh

Quelltext:

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:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject);
begin
close
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
listbox1.clear;
end;

procedure TForm1.Button1Click(Sender: TObject);
var a, b, c, d, e, f: integer;
begin
randomize;
a:=Random(100)+1;
b:=Random(100)+1;
c:=Random(100)+1;
d:=Random(100)+1;
e:=Random(100)+1;
f:=Random(100)+1;

ListBox1.Items.Add(IntToStr(a));
ListBox1.Items.Add(IntToStr(b));
ListBox1.Items.Add(IntToStr(c));
ListBox1.Items.Add(IntToStr(d));
ListBox1.Items.Add(IntToStr(e));
ListBox1.Items.Add(IntToStr(f));

end;

procedure TForm1.Button4Click(Sender: TObject);
var min, pos, i: integer;
begin
listbox1.clear;
with listbox1 do
 begin
 min:=StrToInt(Items[0]);
 Pos:=0    ;
 for i:=1 to Items.count-1 do
  if StrToInt(Items[i]) < min then
   begin
   min:=StrToInt(Items[i]);
   pos:=i;
   Listbox1.Items.add(IntToStr(min));
   end;
  end;
end;


end.


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt

_________________
S.i.d.b. !!!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 30.05.06 20:15 
Kommt der Fehlet bevor du einen Button drückst?

_________________
Markus Kinzler.
_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:17 
user profile iconmara_buh hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
...
listbox1.clear;
with listbox1 do
 begin
 min:=StrToInt(Items[0]);
...




du machst die liste leer und willst auf das erste item zugreifen...

HTH 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
willy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP Pro (SP2), Suse9.3 Pro, Debian6

BeitragVerfasst: Di 30.05.06 20:19 
Ich würde auf das listbox1.clear in Button4 tippen... weil sobald du die For-Schleife startest ist der ListIndex schon überschritten, der wegen dem clear 0 beträgt...


edit: zu spät =/ ^^
mara_buh Threadstarter
Hält's aus hier
Beiträge: 8


Delphi 6
BeitragVerfasst: Di 30.05.06 21:58 
Danke, das problem ist gelöst. Aber jetz hab ich folgendes vor: ich will dem erste Item in der listbox den kleinsten wert, der vorher angezeigten, zu ordnen oder am besten diesen nur vor alle anderen setzten. ich will langsam anfangen, die per zufall ausgewählten werte zu sortieren.Wie ist das umsetzbar??
lg mara_buh
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 30.05.06 22:03 
Suche einfach mal nach QuickSort, Bubblesort, ...

_________________
Markus Kinzler.
_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 22:33 
vielleicht reicht auch TListbox.sortet

HTH 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
fidionael
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 232

Win XP SP2, Ubuntu 6.06
Delphi 7 PE, Delphi 3 Prof
BeitragVerfasst: Di 30.05.06 23:52 
Eine Implementation von QuickSort für Delphi ist aber z. B. auch in Wikipedia bereits vollständig vorhanden - braucht man gar nichts mehr schreiben ;)
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 25.06.06 20:11 
Bei mir kommt dieselbe Fehlermeldung "Listenindex überschreitet Maximum", jedoch mit der Zahl -1. Die ListView ist momentan ohne Funktion, da das Programm noch nicht das Beta-Stadium erreicht hat. Das Phänomen tritt auf, wenn ich in Delphi den Eintragseditor öffne und einen der SubItems anklicke.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 09.07.06 13:33 
Nach einigen Tagen der Ruhe kommt wieder diese Fehlermledung, jedoch mit der Ziffer 2. Ich habe nun eine Funktion eingebaut, dass beim Drüberfahren mit der Maus über die erste Spalte (Caption) ein Hint angezeigt wird. Diesen habe ich jeweils in dem versteckten "SubItems[2]" hinterlegt (da es nur 3 Spalten in der LIstView gibt). Nun erscheint diese Fehlermeldung auch im kompilierten Programm, wenn ich mit der Muas über die Listview drüberfahre.

Soll ich hier noch einen Teilbereich oder den kompletten Code anhängen?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 09.07.06 13:46 
Dann ist der höchste Index der SubItems 1 nicht 2!

_________________
Markus Kinzler.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 09.07.06 13:59 
Ach so, das darf nicht? Dann hab ich ein Beitrag in einem anderen Thema falsch verstanden. Ich hab jetzt eine vierte Spalte hinzugefügt, beim Drüberfahren im kompilierten Projekt erscheint aber immer noch dieselbe Fehlermeldung! Im Eintragseditor selber erscheint nun wieder die alte Fehlermeldung mit der "-1".
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 09.07.06 14:13 
Zeig doch mal ein bischen Code.

_________________
Markus Kinzler.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 09.07.06 14:25 
Ich hab jetzt diese Hint-Funktion wieder ausgebaut, trotzdem braucht das Programm immer noch etwa 25 Sekunden zum eigentlichen Programmstart - vorher wars innerhalb 1 Sekunde da.

"Ein bisschen Code" ist gut - dort steht ja nichts zur TListView1, denn der eigentliche Fehler geschieht ja schon im Eintragseditor (einfach mal ein SubItem anklicken - umbenennen oder löschen diesere Einträge geht auf Grund besagter Fehlermeldung nicht). Daher häng ich das Projekt mal an.


Was mir noch aufgefallen ist:
Eine andere TListView ist jetzt plötzlich komplett leer. Keine Ahnung, warum. Ist mir auch in anderen Projekten schonmal passiert. Da arbeitet man an einem Programm weiter, startet es hin und wieder und irgendwann fehlen sowohl in der kompilierten Fassung als auch in Delphi selbst alle Einträge in der TListView...
Einloggen, um Attachments anzusehen!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 09.07.06 14:42 
Also bei mir lassen sich die SubItems problemlos in der IDE löschen.

_________________
Markus Kinzler.
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: So 09.07.06 14:48 
Mh, ist das dann ein Bug von Delphi 2005 PE?!

Das wäre aber blöd, wenn ich dann jedesmal die TListView neu erstellen müsste...

EDIT:
Ist die TListView2 bei dir leer oder sind Einträge vorhanden?

EDIT 2:
Und wie lange braucht die EXE zum Starten?
CrazyLuke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 247

Windows XP Pro
Turbo Delphi Explorer, D2005 PE
BeitragVerfasst: Sa 11.11.06 13:35 
Dasselbe Problem hbabe ich leider auch bei einem anderen und größeren Projekt, dort wäre das immer neue Erstellen der ganzen TListViews ein sehr großer Aufwand. Es wäre also super, wenn jemand eine andere Lösung wüsste...

_________________
"Was kommt vor 'Schmetterlinge im Bauch'? Raupen im A*sch!" (Bastian Pastewka, "Pastewka", Sat1)
Spansky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 22

Win XP, Kubunto
Delphi 7
BeitragVerfasst: So 22.04.07 22:57 
Bei mir kommt die gleiche/selbe Fehlermeldung. Wisst ihr woran es liegt?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure Doppelt;
var i,p:integer;
begin
  for i:=1 to Form2.ListBox1.Items.Count do
    for p:=i+1 to Form2.ListBox1.Items.Count do
      if not (p=Form2.ListBox1.Items.Count) then
        if Form2.ListBox1.Items[i]=Form2.ListBox1.Items[p] then Form2.ListBox1.Items.Delete(p);
end;
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: So 22.04.07 23:33 
user profile iconSpansky hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure Doppelt;
var i,p:integer;
begin
  for i:=1 to Form2.ListBox1.Items.Count-1 do
    for p:=i+1 to Form2.ListBox1.Items.Count-1 do
      if not (p=Form2.ListBox1.Items.Count) then
        if Form2.ListBox1.Items[i]=Form2.ListBox1.Items[p] then Form2.ListBox1.Items.Delete(p);
end;


Count gibt die Anzahl der Items zurück. Da Items aber nicht bei Index 1 anfängt, sondern bei 0, darf die for-Schleife nur bis max Count -1 laufen!

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 22.04.07 23:39 
Hallo,

außerdem sollte man mit einer for-downto oder while-Schleife arbeiten, wenn man innerhalb der Schleife etwas löscht, denn sonst stimmt Count nicht mehr.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )