Recent

Author Topic: RichMemo BOLDing text example  (Read 2267 times)

Li4KinG

  • Newbie
  • Posts: 3
RichMemo BOLDing text example
« on: April 16, 2020, 09:23:43 pm »
Hello, i have some problems with inserting collored bold text into my richmemo, i tried to do i like in example of colored text from https://wiki.freepascal.org/RichMemo/en :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.AddColorStr(s: string; const col: TColor = clBlack; const NewLine: boolean = TRUE);
  2. begin
  3.   with RichMemo1 do
  4.   begin
  5.     if NewLine then
  6.     begin
  7.       Lines.Add('');
  8.       Lines.Delete(Lines.Count - 1); // avoid double line spacing
  9.     end;
  10.     SelStart  := Length(Text);
  11.     SelText   := s;
  12.     SelLength := Length(s);
  13.     SetRangeColor(SelStart, SelLength, col); // replacing this string of code with SetRangeParams(...)
  14. {    SetRangeParams ( SelStart, SelLength,    
  15.      [tmm_Styles, tmm_Color], // changing Color and Styles only
  16.      '',  // this is font name - it's not used, thus we can leave it empty
  17.      0,  // this is font size - it's font size, we can leave it empty
  18.      col, // making all the text in the selected region 'col' colored
  19.      [fsBold],  // adding Bold
  20.      []
  21.   );}
  22.     // deselect inserted string and position cursor at the end of the text
  23.     SelStart  := Length(Text);
  24.     SelText   := '';
  25.   end;
  26. end;
  27.  
But i got result i didn't unexpected:
What i expect and got with SetRangeColor() using AddColorStr(' this text is green ', clGReen, false);
RichMemo:
textinmemoblablabla this text is green normaltexblablabla

but when i replace SetRangeColor() with SetRangeParams() and use AddColorStr(' this text is green ', clGReen, false); i get my " this text is green " added in new line:
RichMemo:
textinmemoblablabla
this text is green
normaltexblablabla

Why text starting from new line and how i can fix it? Any examples or advice for this code?
I am trying to make a function for filling Richmemo with text not from new line and with color+bold params.

Andriy

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: RichMemo BOLDing text example
« Reply #1 on: April 17, 2020, 04:24:44 pm »
what system? Linux? Windows?

Li4KinG

  • Newbie
  • Posts: 3
Re: RichMemo BOLDing text example
« Reply #2 on: April 21, 2020, 03:07:50 pm »
Windows 8.1 x32(86)
lazarus 2.0.6 r62129

Li4KinG

  • Newbie
  • Posts: 3
Re: RichMemo BOLDing text example
« Reply #3 on: April 21, 2020, 04:57:10 pm »
By the way, RichMemo shows strange behavior when i try to RichMemo1.Lines.Add(myvarstring); in procedure using "for" cycle. When i call procedure first time, richmemo does not change until the end of cycle or until i stop execution  using for example ShowMessage(); and shows all text only after the cycle ended, but in next call of procedure with cycle it works fine (like my memo worked before i changed it to richmemo) and shows lines every iteration of cycle.
I had no problems using memo, but i want to make some of my text colored and bold. Now i think better solution is just search text i want to change after writing it into richmemo.

 

TinyPortal © 2005-2018