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: Di 12.08.08 20:00 
Hallo an alle.
Ich habe ein einfaches Programm, dass etwas zur Stringlist (namens speichern) hinzufügt und speichert. Ich habe auch in meinem Programm eine Funktion, womit man diese wieder öffnen kann. Wenn ich jetzt die Stringlist speicher (unter dem namen bsp.ssyc) dann funktioniert auch alles. Jedoch wenn ich diese Datei wieder öffne, sie verändere und noch einmal speicher, dann wird sie nicht überschrieben. Warum?

Vorher in speichern/ bsp.ssyc: (Beispiel)
ausblenden Quelltext
1:
2:
3:
4:
5:
1
2
3
4
5


Nun füge ich noch 6 und 7 hinzu:
Nachher in speichern/ bsp.ssyc:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
1
2
3
4
5
1
2
3
4
5
6
7


Ich möchte gern dass es überschriebn wird:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
1
2
3
4
5
6
7


Habe in der Eile nicht die Suche benutzt. Ich bitte dies zu Entschuldigen.

MfG Swordooo
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: Di 12.08.08 20:16 
Ne StringList speichert das, was in ihr drin steht, in der Datei. Wenn du mit TStringList.SaveToFile() abspeicherst, wird die Datei IMMER überschrieben.. da wird nix angehängt.
Folglich stehen die Zahlen schon falsch in deiner Stringliste.

user profile iconSwordooo hat folgendes geschrieben:
Jedoch wenn ich diese Datei wieder öffne, sie verändere und noch einmal speicher, dann wird sie nicht überschrieben. Warum?

Warum? Siehe oben. Du fügst alle Zeilen neu in der Stringliste hinzu, nicht nur 6 und 7.
Mehr Infos geht schlecht ohne Code, aber so sollte man den Fehler auch alleine finden können.

_________________
PROGRAMMER: A device for converting coffee into software.
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: Di 12.08.08 20:24 
Keine Ahnung:
Ich habe das zum Speichern: (bischen unsauber, ich hatte hierfür mal eine for-Strunktur...)
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:
procedure TSDIAppForm.BitBtn3Click(Sender: TObject);
begin
savedialog1.Execute;

speichern.Add(StringGrid1.Cells[1,1]);
speichern.Add(StringGrid1.Cells[1,2]);
speichern.Add(StringGrid1.Cells[1,3]);
speichern.Add(StringGrid1.Cells[1,4]);
speichern.Add(StringGrid1.Cells[1,5]);
speichern.Add(StringGrid1.Cells[1,6]);
speichern.Add(StringGrid1.Cells[1,7]);
speichern.Add(StringGrid1.Cells[1,8]);
speichern.Add(StringGrid1.Cells[1,9]);
speichern.Add(StringGrid1.Cells[1,10]);
speichern.Add(StringGrid1.Cells[1,11]);
speichern.Add(StringGrid1.Cells[1,12]);

speichern.Add(StringGrid1.Cells[2,1]);
speichern.Add(StringGrid1.Cells[2,2]);
speichern.Add(StringGrid1.Cells[2,3]);
speichern.Add(StringGrid1.Cells[2,4]);
speichern.Add(StringGrid1.Cells[2,5]);
speichern.Add(StringGrid1.Cells[2,6]);
speichern.Add(StringGrid1.Cells[2,7]);
speichern.Add(StringGrid1.Cells[2,8]);
speichern.Add(StringGrid1.Cells[2,9]);
speichern.Add(StringGrid1.Cells[2,10]);
speichern.Add(StringGrid1.Cells[2,11]);
speichern.Add(StringGrid1.Cells[2,12]);

speichern.Add(StringGrid1.Cells[3,1]);
speichern.Add(StringGrid1.Cells[3,2]);
speichern.Add(StringGrid1.Cells[3,3]);
speichern.Add(StringGrid1.Cells[3,4]);
speichern.Add(StringGrid1.Cells[3,5]);
speichern.Add(StringGrid1.Cells[3,6]);
speichern.Add(StringGrid1.Cells[3,7]);
speichern.Add(StringGrid1.Cells[3,8]);
speichern.Add(StringGrid1.Cells[3,9]);
speichern.Add(StringGrid1.Cells[3,10]);
speichern.Add(StringGrid1.Cells[3,11]);
speichern.Add(StringGrid1.Cells[3,12]);

speichern.Add(Panel1.Caption);
kennung := Extractfileext(savedialog1.FileName);
if kennung = '.ssyc' then
speichern.SaveToFile(savedialog1.FileName)
else  speichern.SaveToFile(savedialog1.FileName + '.ssyc')
end;


Liegt es an dem ganzen? Aus jeden Fall habe ich nocheinmal nachgeguckt und nein, es wird komischerweise nicht überschrieben... muss na mir leigen.

Vorher:
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:
123
456
789
0
0
0
0
0
0
0
0
0
0,5
0,5
0,5
0
0
0
0
0
0
0
0
0
61,5
166,5
166,5
0
0
0
0
0
0
0
0
0
394,5


Nachher:
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:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
123
456
789
0
0
0
0
0
0
0
0
0
0,5
0,5
0,5
0
0
0
0
0
0
0
0
0
61,5
166,5
166,5
0
0
0
0
0
0
0
0
0
394,5
123
456
789
910
0
0
0
0
0
0
0
0
0,5
0,5
0,5
0,5
0
0
0
0
0
0
0
0
61,5
166,5
166,5
60,5
0
0
0
0
0
0
0
0
455


Danke schonmal!
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: Di 12.08.08 20:33 
Äh ja..
Du rufst also mehrmals diese Prozedur, wo du jeweils einige Zeilen ANHÄNGST, auf.
Was erwartest du, dass sich die StringListe nach dem speichern automatisch leert?
ausblenden Delphi-Quelltext
1:
TStringList.Clear;					


Btw: Klick in deinem SaveDialog mal auf "Abbrechen" und staune was passiert ;)
Lösung: TSaveDialog.Execute ist eine Funktion, die einen Boolean-Wert zurückliefert. If-Abfrage drum und fertig.

_________________
PROGRAMMER: A device for converting coffee into software.
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 12.08.08 20:35 
musst halt deine stringlist clearen, bevor du die daten 'n zweites mal reinschreibst ;-)
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: Di 12.08.08 20:36 
Kann ja sein. :lol:
Vielen Dank!!