Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 03.01.06 13:48 
Hallo, ich wollte gerade den Text meines Richedits mit Hilfe von
ausblenden Delphi-Quelltext
1:
Lines.SaveToFile();					

Speichern, jedoch sieht meine Datei dann so aus:
ausblenden Quelltext
1:
2:
3:
{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Fixedsys;}}
\viewkind4\uc1\pard\f0\fs16 
\par }

Woran liegt das ? Wie kann ich das beheben ?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 03.01.06 13:54 
Moin!

Wie man es vielleicht bei einem RichEdit erwarten würde, ist das Suche in: Delphi-Forum, Delphi-Library RICHTEXT-Format. :wink:

cu
Narses
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 03.01.06 14:03 
Was ja nicht verwunderlich wäre, wenn Lines nicht vom Typ TString sind, aber dann wird wohl sämtliches kramsel in den Strings gespeichert, demnach müsste ich den Text abspeichern, was wieder eine StringList erfordert :(

das sollte gehen:
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:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
function RTFToPlainText(RTF:String):String;
var i,j,h:integer;
begin
  //Sonderzeichen ersetzen
  RTF:=StringReplace(RTF,'\'+Chr(39)+'f6','ö',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'d6','Ö',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'e4','ä',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'c4','Ä',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'fc','ü',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'dc','Ü',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'\'+Chr(39)+'df','ß',[rfReplaceAll]);

  //Fontangaben entfernen
  Repeat
    i:=Pos('{\f',RTF);
    if i>0 then
    begin
      j:=i;
      h:=1;
      Repeat
        Inc(j);
        if RTF[j]='{' then
          Inc(h);
        if RTF[j]='}' then
          Dec(h);
      Until ((RTF[j]='}') and (h=0)) or (j=Length(RTF));
      if ((RTF[j]='}') and (h=0)) then
      begin
        Delete(RTF,i,j-i+1);
      end;
    end;
  Until i=0;

  //Andere Formatbefehle entfernen
  i:=1;
  While (i<Length(RTF)) do
  begin

    if RTF[i]='\' then
    begin
      j:=i;
      While (RTF[j]<>' ')
      and (j<Length(RTF))
      and (RTF[j+1]<>'ä')
      and (RTF[j+1]<>'ö')
      and (RTF[j+1]<>'ü')
      and (RTF[j+1]<>'Ä')
      and (RTF[j+1]<>'Ö')
      and (RTF[j+1]<>'Ü')

      do
        Inc(j);
      Delete(RTF,i,j-i+1);
    end
      else Inc(i);
  end;
  RTF:=StringReplace(RTF,#$D#$A,' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,';',' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'{',' ',[rfReplaceAll]);
  RTF:=StringReplace(RTF,'}',' ',[rfReplaceAll]);

  Result:=Trim(RTF);
  if Result='' then
    Result:=' ';
end;
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: Di 03.01.06 14:26 
Hallo,
user profile iconF34r0fTh3D4rk hat folgendes geschrieben:
...demnach müsste ich den Text abspeichern, was wieder eine StringList erfordert :(

das geht auch :wink: :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
RichEdit1.PlainText := True;
RichEdit1.Lines.SaveToFile('c:\temp\_ohne_rtf_code.txt');
//...
RichEdit1.PlainText := False;
RichEdit1.Lines.SaveToFile('c:\temp\_mit_rtf_code.txt');

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 03.01.06 14:27 
wird der rtf text beim zurücksetzen auf false wieder komplett wiederhergestellt ? der muss dann ja zwischengespeichert werden, was denke ich das gleiche ist, wie meine jetzige methode mit stringlist 8)
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: Di 03.01.06 14:36 
Hallo,

Plaintext setzen verändert nicht den RTF-formatierten Text.
Das kannst Du ausprobieren indem du die vier Codezeilen in einer Prozedur ausführst.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 03.01.06 14:38 
danke :D problem wäre dann gelöst, auf zum nächsten ;)