Author Topic: clDefault and text in darktheme  (Read 2395 times)


  • New Member
  • *
  • Posts: 14
clDefault and text in darktheme
« on: July 25, 2020, 09:30:51 pm »
Having trouble making rich text pick up the default color, when the OS theme is darkmode, or high contrast (Win and Mac), where the text has to be white.

If I set the richmemo.font.color to initialize with clDefault, then it draws with system white text.
But any and all changes to the richmemo.font, such as size, or manipulating richtext, then the component uses black text.   When writing anything new to the Font property, causes a new Font object to be created, but it comes out black text every time.  Any attempt to have the component adopt the systems clDefault color is not accepted.  I don't think the richmemo native objects is even capable of accepting clDefault.

How to read the actual color value of clDefault, so I can hard code the text color into rich text edits?


  • Hero Member
  • *****
  • Posts: 3034
  • POKE 54296,15
    • Eye-Candy Controls
Re: clDefault and text in darktheme
« Reply #1 on: July 25, 2020, 09:54:54 pm »
RichMemo is not a native widget so I agree it probably does not understand clDefault..
clDefault is defined as
Code: Pascal  [Select][+][-]
  1. clDefault = TColor($20000000);
so it is therefore interpreted as a black color.
You can do something (function) like
Code: Pascal  [Select][+][-]
  1. if AColor=clDefault
  2.   then richmemo.font.color:=clBtnText // or clWindowText etc.
  3.   else richmemo.font.color:=AColor;
I use this a lot in EC-Controls, so they know clDefault even if they are not native widgets.
Lazarus 2.3.0 rmain-2_3-280-g5db1922e37 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls:


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2720
Re: clDefault and text in darktheme
« Reply #2 on: July 26, 2020, 07:52:40 pm »
It's actually quite an interesting subject you brought up.

As of right now, RichMemo only expects the color to be specified as RGB color.
There's no handling of specially named colors (i.e. clDefault) in the background.
It only happens that clDefault code is the same as black color.


  • New Member
  • *
  • Posts: 14
Re: clDefault and text in darktheme
« Reply #3 on: July 27, 2020, 08:48:20 am »
The TRichMemo descends from a TCustomMemo, and that parent and branch is able to stay with the OS defaults, even after making font size, style changes.  But even using TRichmemo as a plain TMemo, it looses sync with the OS theme font color.   So some inheritance is missing for the TRichMemo.   I'm still looking for the missing piece.

In the meantime, I'm using this handy cheat to discover clDefault; scrape the canvas of a TPanel to get its color.

Code: Pascal  [Select][+][-]
  1.   PanelRichMemoResult.Update;
  2.   ThemeCanvasColor := PanelRichMemoResult.Canvas.Pixels[4,4];
  3.   ThemeFontColor := ContrastColor(ThemeCanvasColor);
  4.   RichMemoResult.Font.Color := ThemeFontColor;

« Last Edit: July 27, 2020, 02:50:51 pm by rossh_lz »


TinyPortal © 2005-2018