DB Access + TRichView

General TRichView support forum. Please post your questions here
Post Reply
asteblev
Posts: 9
Joined: Mon Jan 01, 2007 4:38 pm

DB Access + TRichView

Post by asteblev »

Hi, Sergey. Her is the problem. I use Access to save the RVF files. I`ve a field of type MEMO. But when I load a data from this fiel nothing is going on. Her is the code:

To Save:
main.bufer.SQL.Text := 'update documents set content="" where id_doc=1' ;
main.bufer.ExecSQL ;
ADOTable1.TableName := 'documents' ;
ADOTable1.Open ;
ADOTable1.First ;
ADOTable1.Edit ;
Stream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('content'), bmWrite);
try
RichViewEdit1.SaveRVFToStream(Stream, false);
finally
Stream.Free;
end;
ADOTable1.Post;


To Load:
ADOTable1.TableName := 'documents' ;
ADOTable1.Open ;
ADOTable1.First ;
Stream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('content'), bmRead);
try
RichView1.LoadRTFFromStream(Stream);
RichView1.Format;
finally
Stream.Free;
end;
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Copy content of the field to file and send to me

Code: Select all

ADOTable1.TableName := 'documents' ; 
ADOTable1.Open ; 
ADOTable1.First ; 
Stream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('content'), bmRead); 
try 
  FileStream := TFileStream.Create('c:\problem.rvf', fmCreate);
  FileStream.CopyFrom(Stream, 0);
  FileStream.Free;
finally 
  Stream.Free; 
end;
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Possible reasons:
1) Memo field cannot contain binary data (the document is corrupted)
Solution: select another field type, or exclude rvfoSaveBinary from RichViewEdit1.RVFOptions
2) Styles are not saved with documents (document can be loaded only of RichViewEdit1.Style has the same collections of styles as they were on saving)
Solution: right click RichViewEdit1 in Delphi, choose "Settings", select "Allow adding styles dynamically". Make sure that no other RichView uses the same RVStyle component as RichViewEdit1.
asteblev
Posts: 9
Joined: Mon Jan 01, 2007 4:38 pm

Post by asteblev »

Yes, Sergey, u are right, that field MEMO is wrong. The type must to be OLE. but when I load the data, richview show the text-style and text without formating.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

May be you included rvfoConvUnknownStylesToZero in RichViewEdit1.RVFOptions?
If yes, RVF documents with mismatched styles will be loaded, but all unknown styles (with too large index) will be converted to 0.
asteblev
Posts: 9
Joined: Mon Jan 01, 2007 4:38 pm

Post by asteblev »

Great thank you, Sergey. All is ok.
Post Reply