Container for Richview

General TRichView support forum. Please post your questions here
Post Reply
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Container for Richview

Post by BennieC »

Hi
I am trying to find a container for the contetnts of a Ricgview document.
I have memos in RichEdit format, presumably in the lines property.
This is stored as a Blob in a database, which I now need to retrieve into a Richview component. Once retrieved I want to store the new RichView data again in a new database Blob field. The question is which property of the Richview component contains all of the document data, formatting, etc so that I can use this to manage the transfer of information from one point to another.
I guess I do not understand the RV component well enough and do not find basics in the documentation. Maybe you could assist in explaining how to manage the data contents of a Richview component, outside the component.
Hope this is understandable.
Bennie
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Yes you can use SaveRVFToStream/LoadRVFFromStream to save/load your document to/from BLOB. Your document will be saved with all formattings, pictures, objects... Read manuals, look fro demos.
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Post by BennieC »

Thanks for this.
Let's say I call a procedure that reads the content of the BLOB from the database. How do I pass this content as a parameter back to the calling procedure. Do I pass a RichView component to hold it or is there another structure that I can use to pass this data. I can dump it into a file but that seems quite over the top.
Bennie
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Actually, it's not necessary to convert database to another format. If you will use TDBRichViewEdit component linked to your table, it detects the field format automatically. So, your database may contain old documents in RTF format, new documents in RVF (RichView format), it does not matter.

There is no property representing a document. There are many methods allowing to access objects forming a document. But there is no a special property for a document as a whole. You can only save it and load to a stream.
There is a demo showing how to load and save a document from DB record in TRichViewEdit component. It is in Demos\*\DB Demo\2 RichViewEdit\
The procedures for saving and loading are SaveRVFToField and LoadRVFFromField from Unit2.pas.
These procedures load and save in RVF (RichViewFormat).
For autodetecting loading format, change rv.LoadRVFFromStream to rv.LoadFromStream.

Note: there is a data format that is supported by TDBRichViewEdit, but cannot be loaded by LoadFromStream. It is RTF stored in Unicode memo fields. For such fields, Field.FieldType equals to ftWideMemo. This case requires a special processing for loading in TRichViewEdit. And RichView Format (RVF) cannot be stored in fields of this type.
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Post by BennieC »

Hi
I do not use a DBRVEdit as I would like to leave access to the DB until everyone is happy with the data. I have managed to save and retrieve data from the DB.

My problem is actually outside the DB. If I have a RV in a object but wish to pass it to another object, do I transfer the component in total, or is there another structure. For the moment I dump it into a file and retrieve the file in the second object. I have difficulties in tarnsferring a stream, but that may be the best way.
Bennie
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Streams are the best for copying.

Code: Select all

procedure CopyDoc(Src, Dst: TCustomRichViewEdit); 
var Stream: TMemoryStream; 
begin 
  Stream := TMemoryStream.Create; 
  Src.SaveRVFToStream(Stream, False); 
  Stream.Position := 0; 
  Dst.LoadRVFFromStream(Stream); 
  Stream.Free; 
  Dst.Format; 
end;
BennieC
Posts: 28
Joined: Sat Jun 18, 2011 7:00 pm

Post by BennieC »

Sorry, I obviously don't explain myself well enough
I need to pass the RV as a parameter in a procedure and streams don't work for me
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Why don't they work?
Post Reply