Lazarus

Programming => Packages and Libraries => RichMemo => Topic started by: dbannon on August 05, 2017, 03:13:49 am

Title: [SOLVED] RichMemo bug clearing background colour, linux only
Post by: dbannon on August 05, 2017, 03:13:49 am
Hi Folks,
I find that RichMemo1.SetRangeParams() is unable to clear a background colour after it has been set. Here is simple test case, on a clear form, drop a RichMemo and a button, make the button code look like this -

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.      TP : TFontParams;
  4. begin
  5.     RichMemo1.Clear;
  6.     RichMemo1.Append('Some text, lets highlight');
  7.     TP.BkColor:= clYellow;
  8.     TP.HasBkClr := true;
  9.     RichMemo1.SetRangeParams(3,15,[tmm_BackColor], TP, [], []);
  10.     TP.HasBkClr := false;
  11.     RichMemo1.SetRangeParams(5,13,[tmm_BackColor], TP, [], []);
  12. end;
Under linux (Ubuntu mate, gtk2) the middle section remains highlighted, on windows its restored to unhighlighted, or normal text.

Any thoughts ?

Davo
Title: Re: RichMemo bug clearing background colour, linux only
Post by: skalogryz on August 05, 2017, 03:34:52 am
Instead of setting HasBKColor to false, try to setup bkColor to clDefault
Title: Re: RichMemo bug clearing background colour, linux only
Post by: dbannon on August 05, 2017, 04:44:13 am
Quote
....try to setup bkColor to clDefault

yeah, good idea. Actually, clDefault seems to be black, but $FFFFFF does, apparently achieve what I want. I'm reading the actual text properties to turn it into some xml so I'll need to fiddle to ensure no background colour is the same as a background colour of $FFFFFF but this gets me going again.

Thanks skalogryz.

By the way, are you aware that the certificate for havefunsoft.com has expired ?
Title: Re: RichMemo bug clearing background colour, linux only
Post by: skalogryz on August 05, 2017, 05:00:39 am
Historical note: HasBkColor is a flag to indicate if Params structure has background color field populated or should it be ignored.
Thus in order to clear the background, hasBKColor must be set to true.


Thanks. I got notifications about certificate exporation, several weeks ago, but got lazy. Besides I was planning to change the issuing authority. Should fix it this weekend
Title: Re: RichMemo bug clearing background colour, linux only
Post by: dbannon on August 05, 2017, 05:24:15 am
Quote
Thus in order to clear the background, hasBKColor must be set to true.

Ah, that makes sense. Thanks.

Are you really doing this at 5 am ?   :o

David
Title: Re: RichMemo bug clearing background colour, linux only
Post by: skalogryz on August 05, 2017, 05:28:27 am
It's much more quiet overnight
Title: Re: RichMemo bug clearing background colour, linux only
Post by: dbannon on August 09, 2017, 10:41:10 am
OK Folks, for the record, this is what I do, it works under both Linux and Windows.
This gets called after a user has selected some text, it toggles on and off.

Quote
if RichMemo1.GetTextAttributes(RichMemo1.SelStart, TP) then begin
          TP.HasBkClr := true;
          if  TP.BkColor = clYellow then
              TP.BkColor := $FFFFFF
          else  TP.BkColor := clYellow;
          RichMemo1.SetRangeParams( RichMemo1.SelStart,RichMemo1.SelLength, [tmm_BackColor], TP, [], []);
end; 
TinyPortal © 2005-2018