Hello,
I'm working with Delphi 10.3 and the TRichview controls (18.3). In my current project I encountered a strange problem with TDBRichView und BLOB-Fields.
I have an TRichViewEdit control and need to store the formatted RTF-text to a BLOB-field (Firebird, subtype "text", character set UTF8) via stream (TMemoryStream). For saving the RTF to a stream I use "rve.SaveRTFToStream(bs,False)", for saving the stream to a BLOB-field I use "TBlobField(ds.fieldbyname(s_field)).LoadFromStream(bs)". When I read the content of the BLOB-field via stream and load it into a TRichViewEdit, everything works fine so far. The RTF-text is displayed correctly (1). When I load the stream to TMemo I can see the plain RTF-text (2). It's also okay. But when I bind a TDBRichViewEdit to the datafield the text contains stange characters (chinese, I suppose), and the original RTF-text will not be displayed (3). Because of the architecture of my application I must use streams to store the RTF-text, but sometimes I must use databound TDBRichViewEdit to display it. I have no clue how to handle this problem.
Thank you very much in advance
Norbert Richter
DBRichViewEdit doesn't display correctly BLOB-field
DBRichViewEdit doesn't display correctly BLOB-field
- Attachments
-
- DBRichViewEdit with BLOB-data.jpg (173.52 KiB) Viewed 12245 times
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: DBRichViewEdit doesn't display correctly BLOB-field
Did you try to connect TDBMemo to this field? I believe it will show the same weird text as TDBRichView.
I think this is a wide memo field (Field.DataType = ftWideMemo).
For these fields, TRichView expects RTF stored in UnicodeString.
Data can be stored in this way:
When you need to load this Unicode representation of RTF back, you can simply use rv.LoadFromStream, it can autodetect the format.
I think this is a wide memo field (Field.DataType = ftWideMemo).
For these fields, TRichView expects RTF stored in UnicodeString.
Data can be stored in this way:
Code: Select all
var
bs: TMemoryStream;
sW: UnicodeString;
sA: AnsiString;
bs := TMemoryStream.Create;
// saving RTF
rv.SaveRTFToStream(bs, False);
// loading it to sA
SetLength(sA, bs.Size);
bs.ReadBuffer(PAnsiChar(sA)^, bs.Size);
// converting RTF code to Unicode string sW
sW := UnicodeString(sA); // lossless conversion, because all RTF characters has codes less than 128)
// writing Unicode RTF to TmpStream
bs.Clear;
bs.WriteBuffer(PWideChar(sW)^, Length(sW)*sizeof(WideChar));
// saving to DB
BlobField(ds.fieldbyname(s_field)).LoadFromStream(bs);
bs.Free;
Re: DBRichViewEdit doesn't display correctly BLOB-field
Dear Sergey,
thank you very much for the quick response. Works perfectly now!
Regards
Norbert Richter
thank you very much for the quick response. Works perfectly now!
Regards
Norbert Richter