Page 1 of 1

Loading from RTF stream does not show any data

Posted: Tue Mar 01, 2016 1:11 pm
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

Posted: Tue Mar 01, 2016 1:24 pm
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)

Posted: Tue Mar 01, 2016 3:31 pm
by russ3ell
That worked thank you