If a long RTF sequence (e.g. 150,000 characters) is passed to the TRichEdit control (in XE4), the control does not display text, but instead shows raw RTF code:
{\rtf1\ansi\ansicpg1252\deff0...
What's wrong?
procedure TForm1.Button1Click(Sender: TObject); var RtfText: string; Stream: TStringStream; begin RtfText := GenerateRtfText(); Stream := TStringStream.Create(RtfText); try RichEdit2.PlainText := False; RichEdit2.Lines.LoadFromStream(Stream); //<--- ERROR: RichEdit displays raw RTF-Code // if RtfText is too long if StartsText('{\rtf', RichEdit2.Lines.Text) then begin ShowMessage('Oh no, not converted!'); //WORKAROUND: 2nd try seems to work... //Stream.Position := 0; //RichEdit2.Lines.LoadFromStream(Stream); end; finally Stream.Free; end; end;
For example, with the following RTF generation function:
function TForm1.GenerateRtfText: string; var I: Integer; Stream: TStringStream; const DOES_WORK_COUNT = 10000; DOES_NOT_WORK_COUNT = 15000; begin //Fill RichEdit1.Lines.BeginUpdate; try //for I := 0 to DOES_WORK_COUNT do for I := 0 to DOES_NOT_WORK_COUNT do RichEdit1.Lines.Add(IntToStr(I)); finally RichEdit1.Lines.EndUpdate; end; //Convert to RTF Stream := TStringStream.Create; try RichEdit1.Lines.SaveToStream(Stream); Result := Stream.DataString; finally Stream.Free; end; end;
Edited: Even copy and paste do not work correctly:
This is what I did:
- I copied the generated RichEdit1 content (lines 1..15000 with numbers 1..15000) to the notpad.exe file to remove RTF
- I copied the contents of notepad to RichEdit2
Result:
- only 12773 lines are displayed. Last line is only
12 - If I try to add another char to TRichEdit nothing will happen
- If I delete 10 characters (for each backspace), I can add exactly 10 characters later ...
Is there a hidden character limit for TRichEdit?
source share