[Example] How to store HTML in database
Posted: Tue May 12, 2009 4:29 pm
TDBRichViewEdit can store data in the following formats: RVF, RTF, text, depending on the value of FieldFormat property.
If you store data in another format, such as HTML, you need to process OnSaveCustomFormat and OnLoadCustomFormat events.
Example 1: using TrvHtmlImporter
If your documents have images, this example stores them in the application directory (with autogenerated names, so there will be many unused images). You can process OnImportPicture and OnSaveImage2 events to store them in database instead.
Example 2: using TRvHtmlViewImporter:
All the same, except for
If you store data in another format, such as HTML, you need to process OnSaveCustomFormat and OnLoadCustomFormat events.
Example 1: using TrvHtmlImporter
Code: Select all
procedure TForm1.DBRichViewEdit1SaveCustomFormat(Sender: TCustomRichView;
Stream: TStream; var DoDefault: Boolean);
begin
Sender.SaveHTMLToStreamEx(Stream, ExtractFilePath(Application.ExeName),
'title', 'img', '', '', '', []);
{
or
Sender.SaveHTMLToStream(Stream, ExtractFilePath(Application.ExeName),
'title', 'img', []);
}
DoDefault := False;
end;
procedure TForm1.DBRichViewEdit1LoadCustomFormat(Sender: TCustomRichView;
Stream: TStream; var DoDefault: Boolean);
var s: String;
begin
SetLength(s, Stream.Size);
Stream.ReadBuffer(PChar(s)^, Length(s));
RvHtmlImporter1.LoadHtml(s);
DoDefault := False;
end;
Example 2: using TRvHtmlViewImporter:
All the same, except for
Code: Select all
procedure TForm1.DBRichViewEdit1LoadCustomFormat(Sender: TCustomRichView;
Stream: TStream; var DoDefault: Boolean);
var s: String;
begin
HTMLViewer1.LoadFromStream(Stream);
RVHTMLViewImporter1.ImportHtmlViewer(HTMLViewer1, Sender as TCustomRichViewEdit);
DoDefault := False;
end;