Page 1 of 1
RichView 2 DB
Posted: Mon Sep 04, 2006 9:44 am
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.
Posted: Mon Sep 04, 2006 1:03 pm
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\
Posted: Tue Sep 05, 2006 12:45 pm
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.
Posted: Tue Sep 05, 2006 5:08 pm
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
Posted: Wed Sep 06, 2006 10:37 am
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
Posted: Wed Sep 06, 2006 5:08 pm
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.