?
Solved

Remove RichText formatting

Posted on 2003-03-06
5
Medium Priority
?
314 Views
Last Modified: 2013-11-22
I need an efficient way to remove all RichText formatting from a RTF file (in memory). Something like loading a RTF file into a TStrings and then remove all the \par stuff, but leaving the file as plain text (main content untouched). The fastest it goes, the better.
0
Comment
Question by:Spokyx
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 100 total points
ID: 8078534
Hi,

Try this:

procedure TForm1.Button1Click(Sender: TObject);
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    RichEdit1.PlainText := true;
    RichEdit1.Lines.SaveToStream(ms);
    ms.Position := 0;
    RichEdit1.Lines.Clear;
    RichEdit1.Lines.LoadFromStream(ms);
    RichEdit1.PlainText := false;
  finally
    ms.Free;
  end;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 8078554
Forgot to say: I presume that you already have a rtf file loaded in the Richedit1.
0
 
LVL 17

Expert Comment

by:geobul
ID: 8078596
If you want to load an rtf file from disk here is another version:

procedure LoadRtf(re: TRichEdit; filename: string);
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    re.Lines.BeginUpdate;
    try
      re.Lines.LoadFromFile(filename);
      re.PlainText := true;
      re.Lines.SaveToStream(ms);
      ms.Position := 0;
      re.Lines.Clear;
      re.Lines.LoadFromStream(ms);
      re.PlainText := false;
    finally
      re.Lines.EndUpdate;
    end;
  finally
    ms.Free;
  end;
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  LoadRtf(RichEdit1,'c:\program files\Borland\Delphi5\Demos\RichEdit\overview.rtf');
end;

Regards, Geo
0
 

Author Comment

by:Spokyx
ID: 8083059
No, no. You didn't understand me. I want to remove all RTF formatting AFTER the file was loaded into TStrings (thus, in memory). The code is in a DLL so I don't want to include ComCtrls or whatever, I don't want to include the RichEdit component.

To explain myself better, imagine that I load the whole RTF file into a huge String, and then want to parse it removing all RTF formatting to leave it's content untouched.
0
 

Expert Comment

by:CleanupPing
ID: 9316909
Spokyx:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question