Autor Beitrag
Swordooo
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 119

W2K, Windows XP Professional
Delphi 2005 Personal, Delphi 7 Personal
BeitragVerfasst: Fr 11.07.08 15:16 
Hallo an alle,
Das Problem habe ich schon per Suche gefunden, jedoch wurde ich daraus nicht wirklich schlau *Anfänger-Guck*

Ich habe ein Programm, dass eine TStringList Namens "save" abspeichert, wenn ich auf den Mainmenu-Eintrag "Speichern" klicke. Wenn ich auf den Mainmenu-Eintrag "Laden" klicke, soll er save wieder laden und save.Strings[1] Edit13 zuordnen:

Hier der Quellcode:

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:
const
  ort = 'savedpart1.slr';

procedure TForm1.FormCreate(Sender: TObject);
begin
save := TStringlist.Create;
end;

procedure TForm1.Speichern1Click(Sender: TObject);
begin
with save do begin
  Add(Edit13.Text);
  end;
try
save.SaveToFile(ort);
except
showmessage('Es ist ein Fehler aufgetreten');
end;

end;

procedure TForm1.Laden1Click(Sender: TObject);
begin
try
save.LoadFromFile(ort);
Edit13.Text := save.Strings[1];
except
showmessage('Es ist ein Fehler aufgetreten');
end;
end;

end.


Nun kommt immer dieser Fehler: "Listenindex überschreitet das Maximum (1)."

Danke schonmal im Vorraus

MfG Swordooo
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Fr 11.07.08 15:18 
Das 1. Item in einer Listbox hat die Ordnungszahl 0 ! Du versuchts also das 2. Auszulesen, und das gibt es nicht.

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
Swordooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 119

W2K, Windows XP Professional
Delphi 2005 Personal, Delphi 7 Personal
BeitragVerfasst: Fr 11.07.08 15:21 
ok also muss ich dann anstatt

ausblenden Delphi-Quelltext
1:
Edit13.Text := save.Strings[1];					


ausblenden Delphi-Quelltext
1:
Edit13.Text := save.Strings[0];					


nehmen?
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 11.07.08 15:24 
Diese Frage kannst du dir ganz leicht selbst beantworten, indem du es einfach ausprobierst... ;)

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Swordooo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 119

W2K, Windows XP Professional
Delphi 2005 Personal, Delphi 7 Personal
BeitragVerfasst: Fr 11.07.08 15:25 
was denkst du was ich nach deiner 1. antwort gleich gemacht habe? xD und siehe da es geht.

Danke für die Hilfe

MfG Swordooo
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Fr 11.07.08 16:00 
Prinzipiell sind alle Arrays, Listen etc. immer Nullindiziert - sprich das erste Element hat den Index 0. Ausnahmen sind natürlich Arrays bei denen man den Range selbst angibt.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Fr 11.07.08 16:03 
user profile iconMotzi hat folgendes geschrieben:
Ausnahmen sind natürlich Arrays bei denen man den Range selbst angibt.


Und - leider - als Array aufgefasste Strings.

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: Fr 11.07.08 18:21 
Im Except Teil ne Showmessage zu benutzen is auch nich besonders Schlau!
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 11.07.08 18:44 
Hi,

das With-Statement gilt im allgemeinen als unsauber und kann zu Fehlern führen: www.delphi-forum.de/...p;highlight=unsauber.

Außerdem solltest du dich mal mit Suche in der Entwickler-Ecke CODEFORMATIERUNG auseinandersetzen :roll:

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Sa 12.07.08 00:11 
user profile iconJerk hat folgendes geschrieben:
Im Except Teil ne Showmessage zu benutzen is auch nich besonders Schlau!


Sry, aber das nenn ich ne Unqualifizierte Antwort. Was soll daran nicht schlau sein.

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
delphi10
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 447
Erhaltene Danke: 2

W2K, XP, Vista64, Win7 64
RAD-Studio 2010
BeitragVerfasst: Sa 12.07.08 01:37 
Zitat:
Sry, aber das nenn ich ne Unqualifizierte Antwort. Was soll daran nicht schlau sein.

Ich nehm mal an, dass try exception dazu dient im Fehlerfall eine Fehlerbehandlung aufzurufen oder das Programm sauber zu beenden - ohne Mitwirkung des Anwenders.
Dieser Automatismus wird aber empfindlich durch das notwendige Event (OK-Click) in ShowMessage unterbrochen, bei unbeobachteten Betrieb hängt der Rechner bis in die nächste Steinzeit fest oder bis der Admin seine Turnschuhe anzieht.
Gruß Delphi10

_________________
Salus populi suprema lex esto
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 12.07.08 01:52 
Bei Aktionen, die vom User ausgelöst werden, wie z.B. der Klick auf einen "Laden" Button, darf man doch wohl davon ausgehen, dass ein Anwender vorm Rechner sitzt, der den auftretenden Fehelr bestätigt...
delphi10
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 447
Erhaltene Danke: 2

W2K, XP, Vista64, Win7 64
RAD-Studio 2010
BeitragVerfasst: So 13.07.08 08:26 
Könnte es sein, dass noch andere Variationen - als speziell die hier beschriebene - vorstellbar sind, in denen eine Exception ohne Userbeteiligung ausgelöst werden könnte? Ich hörte davon.
ShowMessage bestenfalls vor einem BreakPoint, wenn der Debugger den Variableninhalt mal wieder nicht rausrücken will, weil der Compiler meinte, optimieren zu müssen.

_________________
Salus populi suprema lex esto
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 16.07.08 12:25 
Es gibt so genannte stille exceptions:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure test;
begin
showmessage ('Meldung1');
raise EAbort.Create('Diese Meldung erscheint nicht');
showmessage ('Diese auch nicht!');
end;


Da bekommt der User garnichts mit