You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect colors retrieved from a style in design mode #102
Why doesn't clHighlight work in DesignTime?
At designtime, clHighlight is simply a system constant. Standard components, such as TLabel, use internal VCL mechanisms that check if a style is enabled in the project options and use the appropriate "Style Hook".
Solution: Use StyleServices
In the component code, where the color is retrieved or used for drawing (usually in the Paint method or a helper function that retrieves the color), the following logic should be used:
uses
Vcl.Themes;
function GetCorrectColor(AColor: TColor): TColor;
var
LDetails: TThemedElementDetails;
begin
Result := AColor;
// Check if styles are enabled (works in both Runtime and DesignTime)
if StyleServices.Enabled then
begin
// Get the color from the style for a specific system color
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(teWindow), AColor, Result) then
begin
// Optional: if GetElementColor doesn't support a specific color,
// you can use dedicated methods for system colors
Result := StyleServices.GetSystemColor(AColor);
end;
end;
end;
Steps:
Color Retrieval Location: Locate the place in the TDzHTMLText code where it parses color tags or sets the default text/background color.
DesignTime Condition: You can use the csDesigning property in ComponentState to force a refresh, but StyleServices.Enabled is usually sufficient in newer versions of Delphi (12.1).
Paint Method: Make sure that the component's Paint method resolves colors just before drawing. If the component caches colors, add a mechanism to clear the cache when changing the style.
Supporting Style Changes in the IDE
For a component to react immediately when you change the style in Project Options, it should handle the CM_STYLECHANGED message:
procedure TCMStyleChanged(var Message: TMessage); message CM_STYLECHANGED;
// In the implementation:
procedure TDzHTMLText.TCMStyleChanged(var Message: TMessage);
begin
inherited;
Invalidate; // Forces a redraw of the component with the new style colors
end;
StyleServices in Delphi 12.1 is aware of the styles selected in the project settings (even if the IDE itself looks different).
Using GetSystemColor maps constants like clHighlight to their equivalents in the currently selected .vsf file.
The following GetStyleColor function correctly retrieves the clHighlight color from the tmMenuItemSelected element
when the style is disabled: $00D77800 (blue color)
When the style is enabled, it retrieves a different color, meaning the function correctly returns the color of the active style.
function GetStyleColor: TColor;
var
LColor: TColor;
begin
// Default color
Result := ColorToRGB(clHighlight);
if StyleServices.Enabled then
begin
// Method 1: Getting the system color directly from a style
// This is most effective in Delphi 12.1 for clHighlight
Result := StyleServices.GetSystemColor(clHighlight);
// Method 2: If you need the color from a specific element (as in StyleControls)
// Get the details for the selected menu item (classic "Highlight")
var LDetails: TThemedElementDetails := StyleServices.GetElementDetails(tmMenuItemSelected);
if StyleServices.GetElementColor(LDetails, ecFillColor, LColor) then Result := LColor;
end;
end;
Below is the original function from the StyleControls component, where the color is taken from the style:
procedure TscSysStyleHook.DrawControlText(Canvas: TCanvas;
Details: TThemedElementDetails; const S: string; var R: TRect;
Flags: Cardinal);
var
ThemeTextColor: TColor;
TextFormat: TTextFormatFlags;
begin
Canvas.Font := SysControl.Font;
TextFormat := TTextFormatFlags(Flags);
if StyleServices.GetElementColor(Details, ecTextColor, ThemeTextColor) then
begin
Canvas.Font.Color := ThemeTextColor;
StyleServices.DrawText(Canvas.Handle, Details, S, R, TextFormat,
Canvas.Font.Color);
end
else
begin
Canvas.Refresh;
StyleServices.DrawText(Canvas.Handle, Details, S, R, TextFormat);
end;
end;
I can still reproduce this with DzHTMLText 6.13 in Delphi 12.2 using the attached TestHTML project and the Material Oxford Blue VCL style.
In Delphi 12, StyleServices without an argument returns TStyleManager.ActiveStyle. The VCL form designer uses TStyleManager.ActiveDesigningStyle. Passing the control as StyleServices(Self) lets VCL select the designer's style when the control is in csDesigning, then resolve the existing system color through GetSystemColor.
The patch updates TDzHTMLText.GetRealColor for text and CanvasProcess for the background of non-transparent controls. It keeps the seFont and seClient checks and the parameterless call on Delphi versions older than 10.4.
I verified the original and patched Win32 runtime packages in a test that loads the actual TestHTML form and sets csDesigning. With Material Oxford Blue the patched package resolved both clWindowText and the custom HTML style's clHighlight to the form's design-time palette. Both builds returned the same colors in normal runtime tests.
Rebuild DzHTMLText_VCL and DzHTMLTextDesign_VCL together when testing in the IDE. The color lookup lives in the runtime package used by the designer.
diff --git a/Source/Vcl.DzHTMLText.pas b
535E
/Source/Vcl.DzHTMLText.pas--- a/Source/Vcl.DzHTMLText.pas+++ b/Source/Vcl.DzHTMLText.pas@@ -1267,7 +1267,7 @@
begin
{$IF Defined(DCC) and Defined(VCL)}
if (Color<>clNone) and (seFont in StyleElements) then
- Result := StyleServices.GetSystemColor(Color)+ Result := StyleServices{$IF CompilerVersion >= 34}(Self){$IFEND}.GetSystemColor(Color)
else
{$ENDIF}
Result := Color;
@@ -1340,8 +1340,8 @@
C.Brush.Color := GetColorresolvingParent
else
{$ELSE}
- if (seClient in StyleElements) {and not (csDesigning in ComponentState)} then- C.Brush.Color := StyleServices.GetSystemColor(Color)+ if seClient in StyleElements then+ C.Brush.Color := StyleServices{$IF CompilerVersion >= 34}(Self){$IFEND}.GetSystemColor(Color)
else
{$ENDIF}
C.Brush.Color := Color;
Activity
digao-dalpiaz commentedon Dec 6, 2025
Please place here the HTML code of the text you showed in the image.
Also enter which Application Theme you are using.
Thanks.
FranmoFR commentedon Dec 6, 2025
Ok :)
TestHTML.zip
digao-dalpiaz commentedon Jan 18, 2026
Hello,
I have checked this issue now.
At design time, when trying to obtain the correct theme color, Delphi is not returning the color according to the selected Theme.
I don't know how the other components are doing, but here, using the same Themes method, it doesn't return the color.
In other words, for now, it only works at runtime.
FranmoFR commentedon Jan 19, 2026
You need to use
StyleServices.Why doesn't
clHighlightwork in DesignTime?At designtime,
clHighlightis simply a system constant. Standard components, such asTLabel, use internal VCL mechanisms that check if a style is enabled in the project options and use the appropriate "Style Hook".Solution: Use
StyleServicesIn the component code, where the color is retrieved or used for drawing (usually in the
Paintmethod or a helper function that retrieves the color), the following logic should be used:Steps:
TDzHTMLTextcode where it parses color tags or sets the default text/background color.csDesigningproperty inComponentStateto force a refresh, butStyleServices.Enabledis usually sufficient in newer versions of Delphi (12.1).Paintmethod resolves colors just before drawing. If the component caches colors, add a mechanism to clear the cache when changing the style.Supporting Style Changes in the IDE
For a component to react immediately when you change the style in Project Options, it should handle the
CM_STYLECHANGEDmessage:StyleServicesin Delphi 12.1 is aware of the styles selected in the project settings (even if the IDE itself looks different).GetSystemColormaps constants likeclHighlightto their equivalents in the currently selected.vsffile.digao-dalpiaz commentedon Jan 24, 2026
The code you provided doesn't work.
StyleServices.GetElementDetails does not exist.
Also, StyleServices.GetSystemColor I'm already using, but it only works at runtime.
FranmoFR commentedon Jan 24, 2026
The following GetStyleColor function correctly retrieves the clHighlight color from the tmMenuItemSelected element
when the style is disabled: $00D77800 (blue color)
When the style is enabled, it retrieves a different color, meaning the function correctly returns the color of the active style.
Below is the original function from the StyleControls component, where the color is taken from the style:
digao-dalpiaz commentedon Jan 24, 2026
I tested all these ways and unfortunately it doesn't work. The correct color is only obtained at runtime!
In designtime, you always end up getting the color according to the default theme.
FranmoFR commentedon Nov 28, 2026
FIXED!
I can still reproduce this with DzHTMLText 6.13 in Delphi 12.2 using the attached TestHTML project and the Material Oxford Blue VCL style.
In Delphi 12,
StyleServiceswithout an argument returnsTStyleManager.ActiveStyle. The VCL form designer usesTStyleManager.ActiveDesigningStyle. Passing the control asStyleServices(Self)lets VCL select the designer's style when the control is incsDesigning, then resolve the existing system color throughGetSystemColor.The patch updates
TDzHTMLText.GetRealColorfor text andCanvasProcessfor the background of non-transparent controls. It keeps theseFontandseClientchecks and the parameterless call on Delphi versions older than 10.4.I verified the original and patched Win32 runtime packages in a test that loads the actual
TestHTMLform and setscsDesigning. With Material Oxford Blue the patched package resolved bothclWindowTextand the custom HTML style'sclHighlightto the form's design-time palette. Both builds returned the same colors in normal runtime tests.Rebuild
DzHTMLText_VCLandDzHTMLTextDesign_VCLtogether when testing in the IDE. The color lookup lives in the runtime package used by the designer.