TRichViewEdit. Modify bold only

General TRichView support forum. Please post your questions here
Post Reply
cointec
Posts: 5
Joined: Sat Nov 14, 2009 6:24 pm

TRichViewEdit. Modify bold only

Post by cointec »

Hello,

I have a TRichViewEdit control and I retrieve the rich text through a TStringStream.

var lRTF: TStringStream;
begin
lRTF := TStringStream.Create('');
try
Editor.SaveRTFToStream( lRTF, False );
Result := lRTF.DataString;
finally
lRTF.Free;
end;

If I only make the text bold, the text is not modified.
Another example, modifying only the size of a table.

Is there any TRichViewEdit option to apply those modifications?

a greeting
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit. Modify bold only

Post by Sergey Tkachenko »

Sorry, I do not understand the question.
Of course, there are many operations for modifying properties of font, paragraphs and objects that do not affect text content.

However, if you save text as RTF, RTF will be different because RTF is not just a plain text, it contains information about text and table properties.

I do not understand, how do you want to apply these changes?
In Editor? or in the resulting RTF string?
cointec
Posts: 5
Joined: Sat Nov 14, 2009 6:24 pm

Re: TRichViewEdit. Modify bold only

Post by cointec »

I edit a text
1.png
1.png (3.09 KiB) Viewed 9108 times

Set as bold text
2.png
2.png (2.25 KiB) Viewed 9108 times

When i save RTF text into TStringStream, the text is not modified:

Code: Select all

function TfEditorRV.TextoRTF: string;
var lRTF: TStringStream;
begin
   lRTF := TStringStream.Create('');
   try
      Editor.SaveRTFToStream( lRTF, False );
      Result := lRTF.DataString;
   finally
      lRTF.Free;
   end;
end;
Editor is TRichViewEdit

If i set as bold text and add a new character its ok. Like this
3.png
3.png (1.51 KiB) Viewed 9108 times
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit. Modify bold only

Post by Sergey Tkachenko »

When i save RTF text into TStringStream, the text is not modified:
Sorry, what do you mean?
Where is the text not modified? in Editor? In RTF string?
cointec
Posts: 5
Joined: Sat Nov 14, 2009 6:24 pm

Re: TRichViewEdit. Modify bold only

Post by cointec »

1. I put the original text in Editor.

2. With the Editor, I only put the text in bold

3. Using the method SaveRTFToStream( TStringStream, Boolean) from Editor. The text recovered have the origal texto

Code: Select all

function TfEditorRV.TextoRTF: string;
var lRTF: TStringStream;
begin
   lRTF := TStringStream.Create('');
   try
      Editor.SaveRTFToStream( lRTF, False );
      Result := lRTF.DataString;
   finally
      lRTF.Free;
   end;
end;
"lRTF.DataString" has the original text

If in addition to making the text bold, I add a character, the RTF text contain the change to bold
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit. Modify bold only

Post by Sergey Tkachenko »

Do you mean that RTF saved at step 3 has non-bold text?

Can you create a simple project to reproduce this problem?
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: TRichViewEdit. Modify bold only

Post by standay »

I tried this and it seems to be working. I'm changing the bold this way:

Code: Select all

procedure TForm1.ToggleBold;
begin
  if rve.GetItemStyle(rve.CurItemNo) <> 1 then
    rve.ApplyTextStyle(1)
  else
    rve.ApplyTextStyle(0);
  rve.Reformat;
end;
Then, using your function:

Code: Select all

function TextoRTF: string;
var lRTF: TStringStream;
begin
   lRTF := TStringStream.Create('');
   try
      form1.rve.SaveRTFToStream( lRTF, False );
      Result := lRTF.DataString;
   finally
      lRTF.Free;
   end;
end;
And this on a button:

Code: Select all

procedure TForm1.Button4Click(Sender: TObject);
begin
  ShowMessage(TextoRTF);
end;
The RTF code returned by the TexttoRTF function is correct as I set or unset bold and click the button that runs the function. When I set the text to bold I see \b in the returned RTF. When I unbold it, the \b goes away in the returned RTF.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRichViewEdit. Modify bold only

Post by Sergey Tkachenko »

So, is the problem solved?
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: TRichViewEdit. Modify bold only

Post by standay »

Sergey Tkachenko wrote: Mon Apr 11, 2022 4:48 pm So, is the problem solved?
My post above was just some test code to try and help the original poster. Not sure if what I tried will help him or not. Stan
cointec
Posts: 5
Joined: Sat Nov 14, 2009 6:24 pm

Re: TRichViewEdit. Modify bold only

Post by cointec »

My mistake, it works fine.

Sorry
Post Reply