RichView 2 DB

General TRichView support forum. Please post your questions here
Post Reply
Aida
Posts: 16
Joined: Mon Sep 04, 2006 6:52 am

RichView 2 DB

Post by Aida »

Hi,

How can I save the whole text wich is written in a richViewEdit with it'a format into database.

Thanks in advance.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

function SaveRVFToField(rv: TCustomRichView; tbl: TDataSet;
  const FieldName: String): Boolean;
var Stream: TStream;
begin
  Stream := tbl.CreateBlobStream(tbl.FieldByName(FieldName), bmWrite);
  try
    Result := rv.SaveRVFToStream(Stream, False);
  finally
    Stream.Free;
  end;
end;

Example:
table.Edit;
SaveRVFToField(RichView1, Table1, 'Document');
table.Post;
See also the demo in
Demos\Delphi\DB Demo\2 RichViewEdit\
Last edited by Sergey Tkachenko on Tue Sep 05, 2006 5:05 pm, edited 1 time in total.
Aida
Posts: 16
Joined: Mon Sep 04, 2006 6:52 am

Post by Aida »

Thanks Sergey, it works well as I want.

Also I want to move RTF From DB 2 RichViewEdit 'The opposite operation', if u please.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Code: Select all

var Stream: TStream; 
begin 
  Stream := tbl.CreateBlobStream(tbl.FieldByName(FieldName), bmRead); 
  try 
    Result := rv.LoadRVFFromStream(Stream);
    rv.Format;
  finally 
    Stream.Free; 
  end; 
end; 
The code above assumes that documents in DB are in RVF (RichView Format), this is a default saving format for TDBRichViewEdit.
If you are not sure about format, use LoadFromStream(Stream, rvynaNo) instead of LoadRVFFromStream
Aida
Posts: 16
Joined: Mon Sep 04, 2006 6:52 am

Post by Aida »

The format I want is RTF , and this will not work if I use ADOTable...
The code you have supplied me with works with BDE Tables NOT ADOTables
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can change to SaveRTFToStream and LoadRTFToStream.

TADOTable is derived from TDataSet, like TTable.
The only used method of table is CreateBlobStream, it is introduced in TDataSet (and, according to the help file, implemented in TCustomADODataSet, ancestor of TADOTable)

If this method does not work, the chosen field type is incorrect for TRichView. It must be of BLOB type.
Post Reply