The crash problem may be because of calling rvHelper.RichView.Reformat.
Change the lines
Code: Select all
lRVHelper.RichView.Reformat;
lRVHelper.RichView.SelectAll;
lRVHelper.RichView.CopyRVF;
FRichView.PasteRVF;
Code: Select all
var Stream: TMemoryStream;
...
Stream := TMemoryStream.Create;
try
lRVHelper.RichView.SaveRVFFromStream(Stream, False);
Stream.Position := 0;
FRichView.InsertRVFFromStreamEd(Stream);
finally
Stream.Free;
end;
If you want to support different character sets, just make all text Unicode.
For example, in your project, I changed:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
// leaving only one text and one paragraph style, and making them Unicode
FRichView.Style := TRVStyle.Create(Self);
FRichView.Style.TextStyles.Clear;
FRichView.Style.ParaStyles.Clear;
FRichView.Style.TextStyles.Add.Unicode := True; // <-- requires document clearing
FRichView.Style.ParaStyles.Add;
FRichView.Clear;
FRichView.Format;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HTMLViewer: THtmlViewer;
HTMLViewImporter: TRVHTMLViewImporter;
lRVHelper: ThaRVReportHelper;
begin
lRVHelper := NewRVReportHelper(nil);
lRVHelper.MailDir := GetMailFolder;
HTMLViewer := THtmlViewer.Create(Self);
HTMLViewer.Parent := Self;
HTMLViewer.LoadFromFile(ExtractFilePath(Application.ExeName)+'a.html');
HTMLViewImporter := TRVHTMLViewImporter.Create(Self);
HTMLViewImporter.ImportHtmlViewer(HTMLViewer, FRichView);
FRichView.Format;
HTMLViewImporter.Free;
HTMLViewer.Free;
end;
In this code, I loaded HTML directly in FRichView. You can use an intermediate RVReportHelper, as before, but copy documents using TMemoryStream instead of the Clipboard.
Suggestions to improve:
1) Call NormalizeRichView after ImportHTMLViewer
2) Create a simple image cache while loading, to prevent downloading the same image again and again (for example, your HTML file contains 99 trans.gif). You can see how it is implemented in RichViewActions (see RichViewActions.pas, FDownloadedPictures)