Autor Beitrag
kuschelfreddy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 14.03.09 18:40 
Hallo ihr alle!

Hab schon wieder eine Frage! :oops: Und zwar will ich den Inhalt eines Memofeldes speichern und die gespeicherte Datei wieder öffnen und deren Inhalt in ein Memofeld einlesen lassen.
Das Speichern habe ich so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var f:textfile;
begin
  if Savedialog1.execute
    then
      begin
        AssignFile(f, Savedialog1.Filename + '.txt');
        Rewrite(f);
        writeln(f, Memo2.text);
        CloseFile(f);
      end;
end;


Das klappt einwandfrei und er liest auch jede Zeile des Memofeldes ein. Jetzt habe ich das Öffnen genau umgekehrt gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var f:textfile;
    zeile:string;
begin
  if opendialog1.execute
    then
      begin
        assignfile(f, Opendialog1.filename);
        Reset(f);
        Readln(f, zeile);
        Memo2.Text:=zeile;
        closefile(f);
      end;
end;


Allerdings liest er dabei nur die erste Zeile der gespeicherten Textdatei ein und nicht den gesamten Inhalt. Wüsste gern, wie ich das ändern kann...
LG Nathalie

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 14.03.09 18:42 
Hallo,

mach es Dir nicht so umständlich und verwende
ausblenden Delphi-Quelltext
1:
2:
3:
memo1.lines.savetofile(Dateiname)
und
memo1.lines.loadfromfile(Dateiname)


Gruß Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 14.03.09 18:42 
Hallo, bei Memos geht das doch von Haus aus:

Schau dir mal Memo1.Lines.SaveToFile und Memo1.Lines.LoadFromFile an. :D

_________________
We are, we were and will not be.
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 14.03.09 18:43 
Und von mir der Copy&Paste-Code mit Memo2:
ausblenden Speichern
1:
2:
if Savedialog1.execute then
  Memo2.Lines.SaveToFile(Savedialog1.FileName);


ausblenden Öffnen
1:
2:
if Opendialog1.execute then
  Memo2.Lines.LoadFromFile(Opendialog1.FileName);


Edit: Ihr müsst praxisnaher sein :tongue: .
kuschelfreddy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 14.03.09 18:44 
Aber dann muss ich den Dateinamen doch von vornherein festlegen oder? Das möchte ich eben nicht, ich möchte den vom Benutzer individuell wählen lassen können...
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Sa 14.03.09 18:45 
user profile iconkuschelfreddy hat folgendes geschrieben Zum zitierten Posting springen:
Aber dann muss ich den Dateinamen doch von vornherein festlegen oder? Das möchte ich eben nicht, ich möchte den vom Benutzer individuell wählen lassen können...

Das Execute bedeutet, dass der Dialog mit "OK" beendet wurde. Dann wurde ein Dateiname festgelegt. Du muss halt nur noch prüfen, ob schon eine Dateierweiterung dran ist.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19345
Erhaltene Danke: 1753

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 14.03.09 18:49 
user profile iconRegan hat folgendes geschrieben Zum zitierten Posting springen:
Du muss halt nur noch prüfen, ob schon eine Dateierweiterung dran ist.
Oder beim Dialog DefaultExt auf txt z.B. setzen, dann wird das automatisch angehängt, wenn keine Erweiterung angegeben wird.
kuschelfreddy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Sa 14.03.09 18:50 
OK, funktioniert, dankeschön! =)
Hier wird man förmlich mit Antworten überhäuft... Super Forum! =)
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 14.03.09 19:05 
user profile iconkuschelfreddy hat folgendes geschrieben Zum zitierten Posting springen:
Hier wird man förmlich mit Antworten überhäuft... Super Forum! =)

Das lag nur daran:
Zitat:
LG Nathalie


:P

_________________
PROGRAMMER: A device for converting coffee into software.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19345
Erhaltene Danke: 1753

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 14.03.09 19:08 
:rofl: :rofl: :rofl:
Da magst du Recht haben. Aber um die Zeit ist auch eher mehr los als nachts oder morgens, was ich merke, weil ich im Moment ja sehr oft hier online bin. ;-)