Autor Beitrag
theoneandonly
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win 98, Suse Linux 9.2

BeitragVerfasst: Mi 07.06.06 22:27 
Hallo, ich bins wieder ;)

Ich hab (wieder mal) ein (für andere ist es wahrscheinlich keins) Problem.
Ich habe einen String, den ich speichern und laden möchte.
Dazu 2 Fragen:

1. Wie speichere ich einen String, egal in welches Format, Hauptsache ich kann ihn wieder auslesen, ohne über einen Speicherdialog zu gehen (Dateiname name.***)?

2. Wie speichere ich in das Verzeichnis des Programms, wenn ich den Pfad nicht kenne?

Danke schonmal!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 07.06.06 22:29 
Zitat:
1. Wie speichere ich einen String, egal in welches Format, Hauptsache ich kann ihn wieder auslesen, ohne über einen Speicherdialog zu gehen (Dateiname name.***)?

IniFile, TRegistry, TextFile
Zitat:
2. Wie speichere ich in das Verzeichnis des Programms, wenn ich den Pfad nicht kenne?
ExtractFilePath( Application.ExeName) liefret dir das Verzeichnis, in dem die Anwendung liegt.

_________________
Markus Kinzler.
theoneandonly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win 98, Suse Linux 9.2

BeitragVerfasst: Mi 07.06.06 23:07 
So, ich hab dabei jetzt folgendes Problem:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TProgram.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 sl:= TStringList.Create;
  try
  sl [1]:=inttostr(aufgaben);
  sl [2]:=inttostr(richtig);
  sl [3]:=inttostr(falsch);
  sl [4]:=inttostr(ngk);
  sl [5]:=inttostr(zeit);
  sl.SaveToFile(ExtractFilePath(Application.ExeName)+'\'+name+'.dat');
  finally
  sl.Free;
  end;
end;


Dann krieg ich ne Fehlermeldung 'ListBox Index out of bounds' oder so.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Mi 07.06.06 23:16 
Hi,
erstmal
user profile icontheoneandonly hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
  sl.SaveToFile(ExtractFilePath(Application.ExeName)+'\'+name+'.dat'); //das hervorgehobene muss weg; extractfilepath fügt automatisch ein \ hinzu					



Die Frage ist was du dir bei den folgenden Code gedacht hast:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  sl [1]:=inttostr(aufgaben);
  sl [2]:=inttostr(richtig);
  sl [3]:=inttostr(falsch);
  sl [4]:=inttostr(ngk);
  sl [5]:=inttostr(zeit);


Sind das in den Klammern Integer-Variablen? Was soll das sl [2]? Mir ist so ein Syntax nicht bekannt und es wird auch wahrscheinlich so nicht gehen. sl.add('blubb'); ist wohl das was du suchst.

Ciao
theoneandonly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win 98, Suse Linux 9.2

BeitragVerfasst: Mi 07.06.06 23:21 
Hab ich auch gemerkt, habs nochmal geändert, jetzt siehts so aus und funktioniert soweit:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TBruchrechentrainer.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 sl:= TStringList.Create;
  try
  sl.Add(inttostr(aufgaben));
  sl.Add(inttostr(richtig));
  sl.Add(inttostr(falsch));
  sl.Add(inttostr(ngk));
  sl.Add(inttostr(zeit));
  sl.SaveToFile(ExtractFilePath(Application.ExeName)+'\'+user+'.txt');
  finally
  sl.Free;
  end;
end;


Die erzeugte Datei hat z.B. diesen Inhalt:

8
1
6
1
6790

Wie les ich den wieder aus und weis den Variablen wieder ihre Werte zu?
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: Mi 07.06.06 23:58 
Hallo,

na, eben andersrum :wink:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 sl:= TStringList.Create;  
  try
  sl.LoadFromFile(ExtractFilePath(Application.ExeName)+'\'+name+'.dat');    
  aufgaben := StrToInt(sL[0]);  
  richtig  := StrToInt(sL[1]);
  //...
  finally  
  sl.Free;  
  end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
theoneandonly Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win 98, Suse Linux 9.2

BeitragVerfasst: Do 08.06.06 00:12 
ja, danke, jetzt funzt alles.