Recent

Author Topic: [SOLVED] RichMemo Bold/Italic Mechanism Q  (Read 4234 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1269
[SOLVED] RichMemo Bold/Italic Mechanism Q
« on: April 25, 2019, 09:59:56 pm »
I am trying to use the RichMemo control. And because documentation is pretty much none existent, I am just struggling to getting this to work.

All I want to do is make any text I select Bold if its not, and normal when it is.

Its for a basic  RTF editor.

Error: Operator is not overloaded: not "Set Of TFontStyle"

CODE THAT DOESN'T WORK.

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm5.btnBoldClick(Sender: TObject);
  3.   var
  4.   fp   :  TFontParams;
  5. begin
  6.   Caption := Format('sel start %d,  sel length %d', [txtRTF.SelStart, txtRTF.SelLength]);
  7.   txtRTF.GetTextAttributes(txtRTF.SelStart, fp);
  8.   if fp.Style = [fsBold] then
  9.      fp.Style := Not [fsBold];  <-- LINE WITH ERROR -->
  10.   else
  11.     fp.Style := [fsBold];
  12.  
  13.   txtRTF.SetTextAttributes(txtRTF.SelStart, txtRTF.SelLength, fp);
  14. end;  
  15.  
  16.  
« Last Edit: April 26, 2019, 11:58:23 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #1 on: April 25, 2019, 10:01:39 pm »
I know that the error "NOT" is not workng, but I don't know what it is supposed to be to make the selected text normal and not bold..

UPDATE:
I even tried using the "-" sign in front of [fsBold], doesn't work
« Last Edit: April 25, 2019, 10:16:42 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

FTurtle

  • Sr. Member
  • ****
  • Posts: 292

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #3 on: April 25, 2019, 10:19:09 pm »
See documentation:

https://freepascal.org/docs-html/current/ref/refsu49.html#x152-17400012.8.5

None of those helped.
Tried exclude even, nothing , compiler doesn't like it
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo Bold/Italic Mechanism Q
« Reply #4 on: April 25, 2019, 10:22:05 pm »
Code: Pascal  [Select][+][-]
  1.      fp.Style := fp.Style - [fsBold];
  2.  
instead of "not [fdBold]"
« Last Edit: April 25, 2019, 10:28:53 pm by skalogryz »

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #5 on: April 25, 2019, 10:37:54 pm »
Code: Pascal  [Select][+][-]
  1.      fp.Style := fp.Style - [fsBold];
  2.  
instead of "not [fdBold]"

That WORKED PERFECTLY... I knew there was supposed to be a '-' sign, but had it wrong.

THANK YOU!!!
 ::)
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #6 on: April 25, 2019, 10:39:09 pm »
UPDATED CORRECT CODE:


Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm5.btnBoldClick(Sender: TObject);
  3.   var
  4.   fp   :  TFontParams;
  5. begin
  6.   Caption := Format('sel start %d,  sel length %d', [txtRTF.SelStart, txtRTF.SelLength]);
  7.   txtRTF.GetTextAttributes(txtRTF.SelStart, fp);
  8.   if fp.Style = [fsBold] then
  9.      fp.Style := fp.Style - [fsBold];
  10.   else
  11.     fp.Style := [fsBold];
  12.  
  13.   txtRTF.SetTextAttributes(txtRTF.SelStart, txtRTF.SelLength, fp);
  14. end;
  15.  
  16.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: RichMemo Bold/Italic Mechanism Q
« Reply #7 on: April 25, 2019, 10:42:28 pm »
Code: Pascal  [Select][+][-]
  1.   if fp.Style = [fsBold] then
  2.      fp.Style := fp.Style - [fsBold];
  3.   else
  4.     fp.Style := [fsBold];
  5.  

What about italic and etc?
Better version:

Code: Pascal  [Select][+][-]
  1.   if fsBold in fp.Style then
  2.      fp.Style := fp.Style - [fsBold]
  3.   else
  4.     fp.Style := fp.Style + [fsBold];
  5.  
« Last Edit: April 25, 2019, 10:53:19 pm by FTurtle »

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #8 on: April 25, 2019, 10:53:53 pm »
Code: Pascal  [Select][+][-]
  1.   if fp.Style = [fsBold] then
  2.      fp.Style := fp.Style - [fsBold];
  3.   else
  4.     fp.Style := [fsBold];
  5.  

What about italic and etc?
Better version:

Code: Pascal  [Select][+][-]
  1.   if fsBold in fp.Style then
  2.      fp.Style := fp.Style - [fsBold];
  3.   else
  4.     fp.Style := fp.Style + [fsBold];
  5.  

I was actually just starting to post the same question.

Even though the code above works, it only worked on if bold or not.
If I try that on italics, it takes the italics away.

So, I have to code so it takes both bold and italic into consideration.

Let me try your suggestion.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #9 on: April 25, 2019, 10:55:34 pm »
nope... that doesn't even work at all like it is.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: RichMemo Bold/Italic Mechanism Q
« Reply #10 on: April 25, 2019, 11:00:21 pm »
I edited my code after you quoted it. Take attention that semicolon at line 2 should be deleted.

FTurtle

  • Sr. Member
  • ****
  • Posts: 292
Re: RichMemo Bold/Italic Mechanism Q
« Reply #11 on: April 25, 2019, 11:16:11 pm »
So, I have to code so it takes both bold and italic into consideration.

Code: Pascal  [Select][+][-]
  1.   if [fsBold, fsItalic] <= fp.Style then

or

Code: Pascal  [Select][+][-]
  1.   if (fsBold in fp.Style) and  (fsItalic in fp.Style) then

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #12 on: April 25, 2019, 11:17:03 pm »
I edited my code after you quoted it. Take attention that semicolon at line 2 should be deleted.

Already got that, still doesn't work

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #13 on: April 25, 2019, 11:21:53 pm »
Got this to work.
Even though it still doesn't address if the selected text was alo italic.

Had to add two parentheses on if statemnt

Code: Pascal  [Select][+][-]
  1.  
  2.  if (fsBold in fp.Style) then
  3.      fp.Style := fp.Style - [fsBold]
  4.   else
  5.     fp.Style := [fsBold];
  6.  
  7.  txtRTF.SetTextAttributes(txtRTF.SelStart, txtRTF.SelLength, fp);
  8.  
  9.  

Now, let see if I can take italics into account now.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

pixelink

  • Hero Member
  • *****
  • Posts: 1269
Re: RichMemo Bold/Italic Mechanism Q
« Reply #14 on: April 25, 2019, 11:33:21 pm »
Okay... found some code that works the way it should.

Even if text is Italic, it leaves it that way.

So, you can use the code for Bold function.

If you want to put the code on an Italics button, just switch out fsBold, for fsItalic

CODE THAT WORKS:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm5.btnBoldClick(Sender: TObject);
  3. var
  4.  fp   :  TFontParams;
  5. begin
  6.  Caption := Format('sel start %d,  sel length %d', [txtRTF.SelStart, txtRTF.SelLength]);
  7.  txtRTF.GetTextAttributes(txtRTF.SelStart, fp);
  8.  
  9.    if (fsBold in fp.Style) then
  10.       txtRTF.SetRangeParams (txtRTF.SelStart, txtRTF.SelLength,[tmm_Styles, tmm_Color],
  11.       ''{font},0{fontsize},clBlack{color},[]{make bold/italic},[fsBold]{remove bold/italic})
  12.    else
  13.       txtRTF.SetRangeParams (txtRTF.SelStart, txtRTF.SelLength,[tmm_Styles, tmm_Color],
  14.       ''{font},0{fontsize},clBlack{color},[fsBold]{make bold/italic},[]{remove bold/italic});
  15.  
  16. end;  
  17.  
  18.  
« Last Edit: April 25, 2019, 11:42:43 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 4.2.0 •  VSSTUDIO(.Net) 2022 • Win11 • 32G RAM • Nvida RTX 4070 Ti Super

 

TinyPortal © 2005-2018