Loading from RTF stream does not show any data

General TRichView support forum. Please post your questions here
Post Reply
russ3ell
Posts: 6
Joined: Tue Mar 01, 2016 8:18 am

Loading from RTF stream does not show any data

Post by russ3ell »

I am probably doing something very simple wrong. I have an RTF document saved within a database as a Blob field. I load this into a string and then stream it into a RichViewEdit document, but nothing is displayed:
MemStream.Clear;
i := length(RTFString) * SizeOf(RTFString[1]);
MemStream.Write(RTFString,i);
if not rve.LoadRTFFromStream(MemStream) then
begin
Result := 'Unable to Load RTF';
Exit;
end;
When debugging i comes out as just over 3700
The RTFReadProperties use the defaults with rvrsAddIfNeeded.

Please help
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) before loading from stream, call Stream.Position := 0;
2) after loading, call rve.Format;
3) I am not sure if it's correct to call MemStream.Write(RTFString,i), change to MemStream.Write(Pointer(RTFString)^,i);
4) One RTF character must be stored in one byte, so RTF cannot be stored in Unicode string, only in AnsiString. So, if RTFString is WideString or UnicodeString or (in Delphi 2009 and newer) String, LoadRTFFromStream will fail.
In the new version of TRichView (16.4 and newer), rve.LoadFromStream (not LoadRTFFromStream!) can read RTF converted to Unicode string. Otherwise, you need assign RTFString to AnsiString (conversion of RTF codes from Unicode String to Ansi String is lossless, because RTF uses only character codes with codes less than 128; some exceptions from this rule are possible, but they are rare)
russ3ell
Posts: 6
Joined: Tue Mar 01, 2016 8:18 am

Post by russ3ell »

That worked thank you
Post Reply