Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 25.01.06 20:46 
Hallo.

Ich habe ein Programm, das den Inhalt von mehreren RTF Edits in den RTF Code umwandelt und diese RTF Codes untereinander in eine einzige Datei speichert.
Wenn der User aus einer anderen Anwendung (z.B. Word) formatierten Text in die Richedits kopiert kommt anscheinend auch das Zeichen, das das Ende einer Datei anzeigt mit rüber und wird dann natürlich auch in die Txt Datei gespeichert.
Wenn ich dann die Textdatei aufmache, dann wird die Datei natürlich nur bis zu dem "falschen" Dateieinde gelesen.

Wie lautet denn der ASCI Code dieses Zeichens, damit ich das entfernen kann.

Danke

_________________
In the beginning was the word.
And the word was content-type: text/plain.
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: Mi 25.01.06 20:56 
War das nicht einfach $00 ? Ansonsten guck dir doch mal die Textdatei im HexEditor an und schau nach, was für ein Zeichen da steht, wo die Anzeige in Notepad aufhört.

_________________
We are, we were and will not be.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 25.01.06 21:21 
Hast du denn da mal einen Hexeitore für mich ? Ich hab den aus der Freeware Sparte von uns genommen, und der hört genau so bei eben diesem Zeichen zu lesen auf. Bzw. er zeigt es bei anderen Dateien nicht an.

_________________
In the beginning was the word.
And the word was content-type: text/plain.
pRoTeUs
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Windows XP prof
Delphi 2005 prof
BeitragVerfasst: Mi 25.01.06 21:40 
Hoi,

vielleicht hilft das hier ja weiter...
msdn.microsoft.com/l...pec/html/rtfspec.asp

mfg
proteus
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: Do 26.01.06 13:11 
Hallo,

durch das einfügen über die Zwischanablage aus Word wird an das Ende des RTF-Formatcodes das ASCII-Zeichen 0 [NUL] angefügt.
Es ist immer das letzte Zeichen in der dann über RichEdit.Lines.SaveToFile gespeicherten Datei, egal an welcher Stelle im richEdit der Text eingefügt wurde.
Mehrmaliges Einfügen erhöht nicht die Anzahl der '0'-Zeichen.
Wenn die Rtf-Datei mit einem um ein Zeichen gekürtzten FileStream gespeichert wird ist das Problem gelöst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var MyFS : TFileStream;
begin
MyFS := TFileStream.Create('c:\Temp\DirektAusFileStream-0.rtf',fmCreate);
try
  RichEdit1.Lines.SaveToStream(MyFS);
  MyFS.Size := MyFS.Size-1;
finally
  MyFS.Free;

Der Code kann auch genutzt werden wenn kein '0'-Zeichen vorhanden ist
(wenn keine Texte aus Word kopiert wurden),
es entstehen dadurch keine Probleme.

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

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 26.01.06 17:12 
Hi Lannes. Dein Code funktionert einwandfrei !! Vielen Dank an dieser Stelle nochmals.

Für mich ergeben sich aber noch 2 fragen, nur so aus Neugier:
1. Wieso kann ich denn dieses letzte Zeichen nicht durch einen StringReplace, der mit ein #0 durch '' ersetzt nicht wegbekommen ?? Das habe ich nämlich versucht.
2. Wieso macht es nichts aus, wenn man kein NULL am Ende der Datei hat, und die Datei trotzdem kürzt ?
(3. Woher weisst du das alles ;-) )

_________________
In the beginning was the word.
And the word was content-type: text/plain.
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: Do 26.01.06 23:12 
Hallo,

zu 1.
StringReplace kenn/nutze ich nicht, aber die sollte IMHO #0 finden,
was hast Du denn an StringReplace übergeben?
Weis jetzt nicht genau wie Du die RTF-Codes zusammensetzt,
das ist auch noch eine Möglichkeit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function GetRTFFromRichEditNoNUL(aRichEdit: TRichEdit): String;
var StrS : TStringStream;
begin
  StrS := TStringStream.Create('');
  try
    aRichEdit.Lines.SaveToStream(StrS);
    Result := StrS.DataString;
    if Result[Length(Result)] = #0 then
      Result := Copy(Result,1,Length(Result)-1);
  finally
    StrS.Free;
  end;
end;

procedure TForm1.AnhaengenClick(Sender: TObject);
var sRTF : String;
begin
  sRTF := GetRTFFromRichEditNoNUL(RichEdit1);
  sRTF := sRTF+GetRTFFromRichEditNoNUL(RichEdit2);
  //weiterverarbeiten
end;


zu 2.
Beispiel-RTF-Ausgabedatei:
ausblenden Quelltext
1:
2:
3:
4:
5:
00000000h: 7B 5C 72 74 66 31 5C 61 6E 73 69 5C 61 6E 73 69 ; {\rtf1\ansi\ansi
--- Schnipp ----
00000080h: 70 61 72 64 5C 66 30 5C 66 73 31 36 20 44 65 6C ; pard\f0\fs16 Del
00000090h: 70 68 69 2D 46 6F 72 75 6D 5C 66 31 20 0D 0A 5C ; phi-Forum\f1 ..\
000000a0h: 70 61 72 20 7D 0D 0A 00                         ; par }...
Es werden immer nach der abschließenden '}'-Klammer 0D und 0A (#13#10, Zeilenumbruch) mitgepeichert, die für den eigentlichen RTF-Code nicht relevant sind.
Habe ich jetzt kein 00 und lösche das letzte Zeichen, dann lösche ich 0A.
Das hat keine Auswirkungen, da ein RTF-Reader 0D und 0A nicht interpretiert.

(zu 3.
:gruebel: hab vor Jahren(zu Win 3.11-Zeiten) ein Programm zum erstellen von Winhelp-Dateien geschrieben,
seit der Zeit kämpfe ich mit den unterschiedlichen Winhelp-Compilern, RTF-Spezifikationen und riched.dll-Versionen/Betriebssystemen.)

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

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 30.01.06 19:12 
Vielen Dank für deine ausführlichen Antworten.
Das alles hat mir wirklich sehr geholfen !!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 31.01.06 18:15 
Nachtrag. Das Problem mit StringReplace und dem ersetzen von #0 wird hier erklärt

_________________
In the beginning was the word.
And the word was content-type: text/plain.