RichEdit bug

edited 8:09AM in FreeReport
Below is the code where the bug is and the solution I propose.
If the length of variable name is equal to it's value minus 1 then the procedure ends prematurely.
procedure TfrRichView.GetRichData(lnum: Integer);
var
  i, j, sum: Integer;
  s, s1, s2: String;
begin
  s := SRichEdit.Lines[lnum];
  sum := 0;
  for i := 0 to lnum - 1 do
  begin
    j := Length(SRichEdit.Lines[i]);
    sum := sum + j + 2;
  end;
  i := 1;
  repeat
    while (i < Length(s)) and (s[i] <> '[') do Inc(i);
    s1 := GetBrackedVariable(s, i, j);
    if i <> j then
    begin
      Delete(s, i, j - i + 1);
      s2 := '';
      CurReport.InternalOnGetValue(s1, s2);
      SRichEdit.SelStart := sum + i - 1;
      SRichEdit.SelLength := j - i + 1;
      SRichEdit.SelText := s2;
      Insert(s2, s, i);
      Inc(i, Length(s2));
    end;
  until i >= Length(s);
  //until i = j;
end;

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.