Can TDBRichViewEdit save html in database?

General TRichView support forum. Please post your questions here
Post Reply
Sam2006
Posts: 1
Joined: Sat Jan 21, 2006 1:11 pm

Can TDBRichViewEdit save html in database?

Post by Sam2006 »

I am writing a program that manage records in my online MySQL - DB about movies, books.

Theres is the field DESCRIPTION in each record that store additional information about each item. Information is stored in html format and I search for it in Internet and want to directly copy to my component. That description is inserted directly to Web page.

When I tried TDBRichView i found that it stores data not in html but as:
"-8 1 3 2 1 0 0 0 0 Options 0 1 0 4 0 0 HTML is OFF 4 1 0 4 0 0 BBCode 0 1 -1 1 0 0 is ON 0 1 0 4 0 0 Smilies are ON"

Is it possible to make TDBRichViewEdit to store info as HTML?
Sergey Tkachenko
Site Admin
Posts: 17499
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

By default, documents are stored in RVF format (internal trichview format). You can change it to RTF or plain text by assigning different value to FieldFormat property.

As for storing in different formats, it's more comlicated, but possible in TRichView since the version 1.9.13

type
TRVCustomFormatEvent = procedure (Sender: TCustomRichView; Stream: TStream; var DoDefault: Boolean) of object;

Events: TDBRichView.OnLoadCustomFormat, TDBRichViewEdit.OnLoadCustomFormat allow loading data from db in your own format. Data should be loaded from Stream to Sender. If it is loaded successfully, set DoDefault to False, otherwise the component will attempt to load RVF/RTF/text.

Event: TDBRichViewEdit.OnSaveCustomFormat allows to save document to db in your own format. If you saved it, set DoDefault to False, otherwise the component will save it according to the FieldFormat property.
Prismax
Posts: 7
Joined: Wed Mar 28, 2007 6:59 pm

Post by Prismax »

I still haven't figured out how to load/save HTML to a database field properly using the onloadcustomformat and onsavecustomformat events.

In the onsavecustomformat I just use the savehtmltostream method and it works fine, because when I look into my DB I see plain html code.

But how can I display the rich content again when loading it into the dbrichviewedit component? If it's loaded again I see plain HTML code, like the "source" view of a website, but not the "design" view of that code.
Prismax
Posts: 7
Joined: Wed Mar 28, 2007 6:59 pm

Post by Prismax »

I've been trying lots of other things, but still haven't found the right way to do this. Can anyone help me about what to do?
Sergey Tkachenko
Site Admin
Posts: 17499
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use TRVHtmlImporter component (you can download it from http://www.trichview.com/resources/)

Assign RVHtmlImporter.RichView := DBRichViewEdit1.

Code: Select all

procedure TForm1.DBRichViewEdit1SaveCustomFormat(Sender: TCustomRichView;
  Stream: TStream; var DoDefault: Boolean);
begin
  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;
The main problem with this code is images, because they all will be stored in the applications' directory. And every time you post changes in DB, new images will be created.
So, if you documents have images, use OnSaveImage2 or OnHTMLSaveImage to save images in another DB table, and OnImportPicture to read them from there.
Post Reply