Autor Beitrag
Wolfgang
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Do 19.01.06 12:04 
Hi!

Ich will den Editor von Windows nachprogrammieren.

Leider habe ich kleine Probleme damit den Text meines Memos in die Datei zu speichern.

Soweit hab ichs bereits:

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:
procedure TForm2.Button1Click(Sender: TObject);
var
  Filename: string;
  outfile: Textfile;
  a: integer;
begin

a:=0;
Filename:=directorylistbox1.directory;
if FileExists(FileName+edit1.Text+'.txt'then
  begin
  if MessageDlg('Die Datei ' + Edit1.Text + '.txt existiert bereits. Wollen Sie sie überschreiben?', mtWarning, [mbYes, mbNo], 0) = mrYes then
    begin
      AssignFile(outfile, filename+Edit1.Text+'.txt');
      Rewrite(outfile);
        repeat
        Writeln(outfile, form1.memo1.lines.strings[a]);
        a:=a+1;
        until form1.memo1.lines.strings[a]='';
      CloseFile(outfile);
    end;
  end;
AssignFile(outfile, filename+Edit1.Text+'.txt');
Rewrite(outfile);
  repeat
  Writeln(outfile, form1.memo1.lines.strings[a]);
  a:=a+1;
  until form1.memo1.lines.strings[a]='';
CloseFile(outfile);

end;


Er speichert immer nur ein Textfile mit einem Enter (leer).
Kann mir bitte wer sagen was der Fehler ist?

thx im Vorhinein!


Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Do 19.01.2006 um 16:51

_________________
Two or three tons of stone can really get you down, and keep you there!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 19.01.06 12:09 
Hmmm. ich weiß nicht, wo dein Fehler liegt. Aber warum nimmst du nicht einfach Memo1.lines.Savetofile('c:\Test.txt');?

_________________
We are, we were and will not be.
Wolfgang Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Do 19.01.06 12:18 
Danke sehr!

Das Problem ist gelöst.

Ich hab den Befehl nicht genutzt, weil ich ihn nicht kannte und nicht in der Hilfe gefunden habe.

thx a lot!

_________________
Two or three tons of stone can really get you down, and keep you there!
Crowbar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Di 07.02.06 13:36 
Hi,
ich möchte das Thema noch einmal aufgreifen.
Ist es möglich, den Inhalt von 2 Memo-Feldern in eine Datei zu speichern und natürlich wieder entsprechend zu laden, damit der Text1 im Memo-Feld1 und Text2 im Memofeld2 steht?

Cu
Crowbar
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 07.02.06 13:41 
Ja.

Du kannst beide 'Lines' von beiden Memos in einer Stringlist zusammenfassen und diese dann abspeichern. Du musst dann aber zwischen erstem Memo und zweitem Memo eine Markierung setzen, um sie beim Laden auseinanderhalten zu können.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Crowbar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Di 07.02.06 13:58 
Das ist ein guter Anhaltspunkt. Ich werde es austesten.
(Ich hoffe, dass der Programmier-"Aufwand" nicht zu gross wird. :roll: )

Dankeschön.

Cu
Crowbar
Crowbar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Di 07.02.06 15:54 
So,
den folgenden Code habe ich getestet und funktioniert. :D
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:
...
Var
 memoAll : TStringList;
...
procedure TForm1.SpeicherBtnClick(Sender: TObject);
begin
  memoAll:=TStringList.Create;
  memoAll.Add('Memo 1:');                        { Marker 1 setzen }
  memoAll.AddStrings(Memo1.Lines);
  memoAll.Add('Memo 2:');                        { Marker 2 setzen }
  memoAll.AddStrings(Memo2.Lines);
  memoAll.Add('Memo 3:');                        { Marker 3 setzen }
  memoAll.AddStrings(Memo3.Lines);
  memoAll.SaveToFile('F:\Text.txt');
  memoAll.Free;
end;

procedure TForm1.LadenBtnClick(Sender: TObject);
Var
 x,m1,m2,m3 : Integer;

begin
  Memo1.Clear;
  Memo2.Clear;
  Memo3.Clear;
  memoAll:=TStringList.Create;
  memoAll.LoadFromFile('F:\Text.txt');
  for x:=0 to memoAll.Count-1 do
   begin
     m1:=memoAll.IndexOf('Memo 1:');     { Position der Marker finden }
     m2:=memoAll.IndexOf('Memo 2:');
     m3:=memoAll.IndexOf('Memo 3:');
   end;
  for x:=m1+1 to m2-1 do Memo1.Lines.Add(memoAll.Strings[x]);
  for x:=m2+1 to m3-1 do Memo2.Lines.Add(memoAll.Strings[x]);
  for x:=m3+1 to memoAll.Count - 1 do Memo3.Lines.Add(memoAll.Strings[x]);
  memoAll.Free;
end;

Natürlich müssen noch die entsprechenden Fehlerbehandlungsroutinen eingebaut werden.

Cu
Crowbar

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt


Zuletzt bearbeitet von Crowbar am Di 07.02.06 16:13, insgesamt 1-mal bearbeitet
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 07.02.06 15:59 
user profile iconCrowbar hat folgendes geschrieben:
So,
den folgenden Code habe ich getestet und funktioniert. :(
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:
...
Var
 memoAll : TStringList;
...
procedure TForm1.SpeicherBtnClick(Sender: TObject);
begin
  memoAll:=TStringList.Create;
  memoAll.Add('Memo 1:');                        { Marker 1 setzen }
  memoAll.AddStrings(Memo1.Lines);
  memoAll.Add('Memo 2:');                        { Marker 2 setzen }
  memoAll.AddStrings(Memo2.Lines);
  memoAll.Add('Memo 3:');                        { Marker 3 setzen }
  memoAll.AddStrings(Memo3.Lines);
  memoAll.SaveToFile('F:\Text.txt');
  memoAll.Free;
end;

procedure TForm1.LadenBtnClick(Sender: TObject);
Var
 x,m1,m2,m3 : Integer;

begin
  Memo1.Clear;
  Memo2.Clear;
  Memo3.Clear;
  memoAll:=TStringList.Create;
  memoAll.LoadFromFile('F:\Text.txt');
  for x:=0 to memoAll.Count-1 do
   begin
     m1:=memoAll.IndexOf('Memo 1:');     { Position der Marker finden }
     m2:=memoAll.IndexOf('Memo 2:');
     m3:=memoAll.IndexOf('Memo 3:');
   end;
  for x:=m1+1 to m2-1 do Memo1.Lines.Add(memoAll.Strings[x]);
  for x:=m2+1 to m3-1 do Memo2.Lines.Add(memoAll.Strings[x]);
  for x:=m3+1 to memoAll.Count - 1 do Memo3.Lines.Add(memoAll.Strings[x]);
  memoAll.Free;
end;

Natürlich müssen noch die entsprechenden Fehlerbehandlungsroutinen eingebaut werden.

Cu
Crowbar


Warum machst du dann einen Smiley der traurig guckt? :gruebel: --> :(

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Crowbar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Di 07.02.06 16:12 
Ups, da habe ich mit wohl vertippt! 8)

Cu
Crowbar

P.S. Schon geändert!
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 17:38 
Titel: frage...
Hallo zusammen...

ich hab ein problem und bitte deshalb um hilfe

ich möchte einen memo text in eine text dati speichern, habe auch bereits die letzten beiträge zum thema angesehn, habe aber das problem, dass ich den text in einen bestimmten pfad speichern möchte und diesen nicht vorher im quelltext deklarieren möchte, deshalb hilft mir leider auch dieser beitrag nicht weiter:

"Aber warum nimmst du nicht einfach Memo1.lines.Savetofile('c:\Test.txt');?"

denn soweit war ich leider schon...
wie gesagt möchte ich den pfad auswälen können, in einem popupfesnter oder so...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 21.02.06 17:42 
So:
ausblenden Delphi-Quelltext
1:
memo1.lines.savetofile(edit1.text);					

Der Pfad steht hier in edit1.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 17:47 
habe eien möglichkeit selber herausgefunden... für alle die#s wissen wollen :

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var temp : string;
begin
temp := edit1.text ;
memo1.Lines.SaveToFile(temp);
showmessage ('Gespeichert')
end;


dann brauch man den pfad nur noch in ein editfenster schreiben,
fände ein popupfenster aber schöner, also wenn es irgentwer weiß, dann bitte sagen...

dankeschön...

Moderiert von user profile iconGausi: Beitragsformatierung überarbeitet.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 21.02.06 17:49 
Was verstehst du unter einem Popup?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 17:49 
sorry, habe deinen beitrag zu spät gesehn... danke trotzdem
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 17:51 
wenn man ein normales word dokument öffnet, dann öffnet sich ein fenster, bei welchem man den pfad auswählen kann... so hätte ich mir das gewünscht, ist das nicht ein popupfenster ???
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 21.02.06 18:00 
Das ist ein SaveDialog. Setz einen aufs Formular und schreib
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if savedialog1.execute then
begin
memo1.lines.savetofile(savedialog1.filename);
end;

Schau dir mal im OI die Properties des SaveDialogs an (Filter,InitialDir usw.)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 18:14 
habe diesen befehl schon in meinem buch vorgefunden, wusste ihn aber nicht anzuwenden, was bedeutet der "execute" befehl und wie muss ich das "dialog" verstehen ???
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 21.02.06 18:19 
Lies das so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
//wenn der Savedialog geschlossen wurde, 
if savedialog1.execute then
begin
//Den Text in dem Pfad speichern, der ausgewählt wurde (savedialog1.filename)
memo1.lines.savetofile(savedialog1.filename);
end

Funzt das denn?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
zivi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Di 21.02.06 18:29 
hab ich noch nicht ausprobiert, wollte erst das system verstehen...

muss ich denn nicht erst den memotext als mein Savedialog deklarieren oder weiß delphie sofort was ich speichern möchte ??? ich glaub nicht und deshalb wollt ich das erst verstehen, mein quelltext sagt mir nämlich, wie soll es auch anders, undefinierter bezeichner...

werd mich aber noch mal mit der methode dran versuchen ...


interessenfrage : wie kommst du an delphie ?? schule ?? ich ja ich arbeite mit borland delphi, projektorientierte programmierung, dem ersten band, informatik grundkurs stufe 11
sitze im moment an meiner facharbeit, die mit einer klausur gleichzusetzen ist...
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 21.02.06 18:35 
Wo undefinierter Bezeichner?
Du musst da nix deklarieren oder so.
Wir hatten delphi in der Schule.
Ich hab mir ein Buch aus der Bibliothek geliehen.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot