Page 1 of 1

RTF issue in TRichViewEdit when created run-time

Posted: Thu May 22, 2025 1:08 pm
by fatih
This code works perfectly:

Code: Select all

begin
  MyRichView.Style := RVStyle1;
  OpenDialog1.DefaultExt:='rtf';
  OpenDialog1.Filter:='RTF Document (*.rtf)|*.rtf';
  if OpenDialog1.Execute then
  begin
    MyRichView.Clear;
    MyRichView.LoadRTF(OpenDialog1.FileName);
    MyRichView.Format;
  end;
end;
This loads RTF file without font styles (like plain text):

Code: Select all

var
  MyRichView: TRichViewEdit;
begin
  MyRichView := TRichViewEdit.Create(Self);
  MyRichView.Parent := Self;
  MyRichView.Align := alClient;
  MyRichView.Style := RVStyle1;

  OpenDialog1.DefaultExt:='rtf';
  OpenDialog1.Filter:='RTF Document (*.rtf)|*.rtf';
  if OpenDialog1.Execute then
  begin
    MyRichView.Clear;
    MyRichView.LoadRTF(OpenDialog1.FileName);
    MyRichView.Format;
  end;
end;
Any idea is appreciated.

Re: RTF issue in TRichViewEdit when created run-time

Posted: Thu May 22, 2025 9:08 pm
by standay
Only thing I can think of is check the run-time rve RTFOptions and make sure they match the rve RTFOptions that works.

Stan

Re: RTF issue in TRichViewEdit when created run-time

Posted: Thu May 22, 2025 9:22 pm
by Sergey Tkachenko
The default property values are not optimal for RTF reading.
Unfortunately, they cannot be changed because of possible compatibility problems. Instead, optimal property values are assigned when the component is placed on a form at desigtime.
Assign

Code: Select all

MyRichView.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
MyRichView.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;

Re: RTF issue in TRichViewEdit when created run-time

Posted: Thu May 22, 2025 9:33 pm
by fatih
Sergey Tkachenko wrote: Thu May 22, 2025 9:22 pm The default property values are not optimal for RTF reading.
Unfortunately, they cannot be changed because of possible compatibility problems. Instead, optimal property values are assigned when the component is placed on a form at desigtime.
Assign

Code: Select all

MyRichView.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
MyRichView.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
It worked! Thank you all.