Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi RTF to plain text (without formats) (https://www.delphipraxis.net/112611-rtf-plain-text-without-formats.html)

GuenterS 24. Apr 2008 10:45


RTF to plain text (without formats)
 
Hallo,

ich habe in einem Datenbankfeld den Inhalt eines RichText Feldes mit all den Formatierungsanweisungen. Gibt es eine einfache Möglichkeit diese komplett zu entfernen und damit nur den unformatierten Text zu bekommen?

mkinzler 24. Apr 2008 10:49

Re: RTF to plain text (without formats)
 
In TRichEdit gibt es dafür die Eigenschaft .PlainText;

GuenterS 24. Apr 2008 11:47

Re: RTF to plain text (without formats)
 
Hm, das habe ich schon versucht, bin aber schon daran gescheitert den Text überhaupt in die TRichEdit Komponente zu bekommen.

Ich verwende übrigens Delphi5 Enterprise ... die Turbo Delphi Professional Version habe ich nur privat.

Ich habs so probiert:
Delphi-Quellcode:
var
  lText, lText2: string;
begin
   ...
   lText := GetText(); //Hier ist der RTF Formatierte Text drinnen
   ...

   with TRichEdit.Create(nil) do
   try
      Parent := Self;
      Lines.Text := lText; //<--- Das will er so nicht
      PlainText := true;
      lText2 := Lines.Text;
   finally
      Free;
   end;
end;

mkinzler 24. Apr 2008 11:54

Re: RTF to plain text (without formats)
 
-was meinst du mit will er nicht?
TDBRichEdit ?

GuenterS 24. Apr 2008 12:00

Re: RTF to plain text (without formats)
 
Nein ich meinte schon TRichEdit.

Es kommt zur Laufzeit eine Meldung, dass man so keine lines hinzufügen kann. Kompilierbar ist es aber.

mkinzler 24. Apr 2008 12:11

Re: RTF to plain text (without formats)
 
Hast du mal die db-aware Variante getestet?

Poelser 24. Apr 2008 12:23

Re: RTF to plain text (without formats)
 
Diese Funktion mal probieren:

Delphi-Quellcode:
function RTF2PlainText(s: Integer): string;
var
  RichEdit: TRichEdit;
begin
  RichEdit := TRichEdit.CreateParented(HWND(-3));
  try
    with RichEdit do
    begin
      SelectAll;
      SelText := s;
      Result := Text;
    end;
  finally
    RichEdit.Free;
  end;
end;

GuenterS 24. Apr 2008 12:51

Re: RTF to plain text (without formats)
 
@MKinzler:

Ich bin mir nicht ganz sicher, man zum Entfernen der Rich Text Formatierungen jetzt eine Datenbank dazumachen muss... bzw. sehe ich jetzt den Sinn dahinter nicht, was mir die Datenbankgebunden Version der RichText Komponente helfen soll.



@Poelser:
Deine Funktion hat leider nur den Nachteil, dass im Ergebnis immer noch die RTF Formatierung enthalten ist.

mkinzler 24. Apr 2008 12:54

Re: RTF to plain text (without formats)
 
Zitat:

Zitat von GuenterS
@MKKinzler:

Ich bin mir nicht ganz sicher, man zum Entfernen der Rich Text Formatierungen jetzt eine Datenbank dazumachen muss... bzw. sehe ich jetzt den Sinn dahinter nicht, was mir die Datenbankgebunden Version der RichText Komponente helfen soll.

Zitat:

Ich habe in einem Datenbankfeld...

Poelser 24. Apr 2008 12:57

Re: RTF to plain text (without formats)
 
Zitat:

Zitat von GuenterS
@Poelser:
Deine Funktion hat leider nur den Nachteil, dass im Ergebnis immer noch die RTF Formatierung enthalten ist.

War ja auch aus dem Bauch heraus. Probier mal vor Result := noch ein PlainText := True.

GuenterS 24. Apr 2008 13:06

Re: RTF to plain text (without formats)
 
Das habe ich probiert (mit true and false), aber das hat auch nichts gebracht.

Poelser 24. Apr 2008 13:20

Re: RTF to plain text (without formats)
 
Das habe ich mal schnell in leeres Projekt eingebaut:

Delphi-Quellcode:
function RTF2PlainText(s: String): string;
var
  RichEdit: TRichEdit;
begin
  RichEdit := TRichEdit.CreateParented(HWND(-3));
  try
    with RichEdit do
    begin
      SelectAll;
      SelText := s;
      Result := Text;
    end;
  finally
    RichEdit.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  rtf: string;
begin
  rtf := '{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil Arial;}{\f1\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\f0\fs18 Ein Testtext\par \f0\par }';
  ShowMessage(RTF2PlainText(rtf));
end;
Es funktioniert anstandslos. Ich habe das Gefühl, dass du entweder kein "richtiges" RTF hast, oder deine RichEd32.dll in deinem Windows macht da Mist. :?

marabu 24. Apr 2008 13:23

Re: RTF to plain text (without formats)
 
Hallo Günter,

schau mal hier: Plaintext aus RTF auslesen

Freundliche Grüße

xaromz 25. Apr 2008 09:05

Re: RTF to plain text (without formats)
 
Hallo,

irgendwo in den Tiefen meines MWKEdit habe ich einen RTF-Parser versteckt. Den kannst Du Dir ja mal anschauen.

Gruß
xaromz


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:54 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz