Unmatched Brace error when using rv.LoadRTFFromStream

General TRichView support forum. Please post your questions here
Post Reply
dakota
Posts: 35
Joined: Tue Jan 13, 2009 11:25 pm

Unmatched Brace error when using rv.LoadRTFFromStream

Post by dakota »

Hello:

When I try to load the following rtf text into an TRichView using LoadRTFFromStream, I get an Unmatched Brace error..... however, the exact same string displays fine when read by a DBRichViewEdit from a CLOB field.

What is wrong with the rtf string? And why does it work from a CLOB field but not from a TRichView?

Thanks,

Dale

Code: Select all

      Text := '{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par}';
      Stream := TMemoryStream.Create;
      try
        rv.Clear;
        rv.DeleteUnusedStyles(True, True, True);
        Stream.Write(Text[1], Length(Text));
        Stream.Position := 0;
        if not(rv.LoadRTFFromStream(Stream)) then begin
          nError := rv.RTFReadProperties.ErrorCode;
          if nError = rtf_ec_OK then begin
            MessageBox(0, 'OKAY', '', MB_ICONINFORMATION or MB_OK or MB_APPLMODAL);
          end else begin
            MessageBox(0, 'Error', '', MB_ICONINFORMATION or MB_OK or MB_APPLMODAL);
          end;
        end;
        rv.Format;
        Text := GetAllText(rv);
      finally
        FreeAndNil(Stream);
      end;
[/code]
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Version of Delphi?
Type of Text variable?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The most probably, you use Unicode version of Delphi (2009, 2010 or XE), and Text is defined as String, i.e. it is Unicode, 2 bytes per character.

In this case
- Stream.Write(Text[1], Length(Text)) saves only 1/2 of Text, because the size in bytes is Length*2
- TRichView cannot read RTF written as Unicode string.

Solution: define Text as AnsiString.
dakota
Posts: 35
Joined: Tue Jan 13, 2009 11:25 pm

Post by dakota »

That was it! I was using a string in Delphi 2009.

Many Thanks!

Have a great weekend.

Dale
Post Reply