delphidelphi-xe2tlabel

Delphi XE2 TLabel glowsize causes graphic issue on top left corner of the screen


Ever since porting an app from XE to XE2 I noticed a strange bug, just opening the form in the ide or running the app, a white square box is drawn on the top left corner of the screen (out of the form), which goes away upon hovering the mouse or a window over. I tracked this down to TLabel, simply dropping one on the form and setting Glowsize above 0 causes the issue.

I reinstalled and updated to the last XE2 update3 and the issue still occurs. Anyone has a clue what's going on?

example 1

example 2

enter image description here


Solution

  • The problem starts in TCustomLabel.AdjustBounds with a call to DoDrawText with the screen's device context and the flag DT_CALCRECT. So if anything paints on that device context, it will be painted onto the screen. The DT_CALCRECT flag should prevent that but the DrawThemeTextEx call in Vcl.Themes.TUxThemeStyle.DoDrawText seems to ignore the DT_CALCRECT + LOptions.dwFlags DTT_CALCRECT and paints onto the device context where it should only calculate the required rectangle. I don't know why DrawThemeTextEx does that (yet), but it is a starting point.

    UPDATE 1:
    Delphi 2009 doesn't seem to be affected by this but also calls DrawThemeTextEx. The only difference I see is that all unused fields of the Options record are zero whereas in Delphi XE2 they contain garbage. Maybe DrawThemeTextEx needs them to be zero.

    UPDATE 2:
    The difference between Delphi 2009 and XE2 is that in Delphi 2009 not only DTT_CALCRECT is specified but also DTT_COMPOSITE.

    In Delphi 2009 the DTT_COMPOSITE is always set:

    Options.dwFlags := DTT_TEXTCOLOR or DTT_COMPOSITED or DTT_GLOWSIZE;
    

    whereas in XE2 the flag is only set if the label is painted on glass:

      if csGlassPaint in ControlState then
        Include(LFormat, tfComposited);