9

I guess this is yet another reason why VCL styles are not ready to be really used.

TDateTimePicker control looks fine without VCL styles. Turn on any vcl style, and I get this appearance:

enter image description here

I can turn off the vcl styles for just this component type, by registering a style hook, but that looks really ugly.

This is on Delphi XE2 with update 4 installed.

Ideally, I hope there is a workaround, or some properties of the datetime picker, or some subclass of datetimepicker I could do to force the datetime picker to paint and theme correctly.

Note that normal comboboxes are theming correctly. Note that this reproduces easily in the most minimal sample project imaginable. Yes. It's Yet Another Styles bug.

Update It might be platform specific, related to Windows Common Controls versions on Windows Server 2008 R2 without Aero ("Desktop Experience" in Windows server component terms). It just occurred to me after other people cannot reproduce it, to try this on several different Windows machines. After I did that, I find that the problem only reproduces on Windows Server 2008 R2. Some of our customers use Windows Server 2008 R2. As you know a major reason for using VCL Styles is that it makes your app look the same regardless of what the windows theme is. However in the case above, the whole app themes properly, except the DateTimePicker control, which is themed incorrectly, and only on Windows Server 2008 R2. The same XE2-based demo app works fine on Windows 7.

Both the working and non-working systems have a ComCtl32.dll in the SysWow64 folder with version reading 5.82.7601.17514. However, clearly the native layout and appearance of these controls is different, when VCL themes are off, and this affects the skinning code, which fails.

Update2: Reported as a bug: QC Entry 106783

Warren P
  • 65,725
  • 40
  • 181
  • 316
  • Some time ago, I tried to use VCL styles but ran into some unexpected problems that didn't feel like they were "mine" - rather they seemed to be in the VCL Styles code itself. Of course, what programmer thinks his own code is causing the problem? :-) Our need for styles wasn't urgent, and being pressed for time, I abandoned the effort. Your words "I guess this is yet another reason why VCL styles are not ready to be really used," reminded me of all this. Googling around just now, I didn't see anything indicating that VCL styles had problems. Can you clarify your statement? – RobertFrank Jun 27 '12 at 15:33
  • 4
    @Robert Search on Stack Overflow and QC for VCL styles and you will see that this feature is a bug ridden pre-alpha quality feature. Just like FMX. – David Heffernan Jun 27 '12 at 15:35
  • @WarrenP if you issue is no the same to the described on this [question](http://stackoverflow.com/questions/10335310/style-properties-for-tdatetimepicker) can you provide a simple source code to reproduce the bug. – RRUZ Jun 27 '12 at 15:59
  • @RRUZ: No typing of source code needed. Create new application. Drop a TDateTimePicker on it. Select a VCL theme in the Project settings. Run Project. Bug reporduces, at least on my machine on XE2 update4. – Warren P Jun 27 '12 at 18:45
  • I've been trying to reproduce this for a while with different styles and cannot. I'm running XE2 Update 4 on version `16.0.4429.46931`. Perhaps upload your exact `*.vsf` style so someone can try it out? In the mean-time, I discovered another bug in the `TDateTimePicker` but it's unrelated. – Jerry Dodge Jun 27 '12 at 18:45
  • 2
    Okay it might be platform specific. Windows Server 2008 R2 without Desktop Experience (Aero) . – Warren P Jun 27 '12 at 18:48
  • 2
    Eureka, I just copied my test app to a Windows Server 2008 R2 box and tried, and reproduced your problem. – Jerry Dodge Jun 27 '12 at 18:57
  • It seems we have a difference in behaviour and implementation in the underlying Windows Common Controls library. Notice that on Win7 the default appearance at designtime does not look like a combobox, when you put this control on the design surface. On Windows 2008 R2, this control looks like a normal combobox, until you drop it down. – Warren P Jun 27 '12 at 19:19
  • The strangest on the whole thing is that it should have nothing to do with the Windows common control rendering. It should be under the direction of the VCL style hooks (if I get it right). So I would really bet on the custom hook like shown in the answer to the question what RRUZ linked in his comment. Have you tried it anyway ? – TLama Jun 27 '12 at 19:27
  • It's opposite to the case mentioned in RRUZ's link. In my case, it breaks when Windows themes are already turned off. – Warren P Jun 27 '12 at 19:32
  • If you apply the "Classic Style" to the Windows 7 this issue appears too :( – RRUZ Jun 27 '12 at 19:32
  • Oh. So I need a ClassicDetection, and forget about server OS. – Warren P Jun 27 '12 at 19:33
  • 1
    And they just removed Aero glass completely (and maybe the theme service?) in Windows 8. This is going to be SO much fun. – Warren P Jun 27 '12 at 19:39
  • 1
    @WarrenP I don't think you have that right. The Windows 8 Aero change is in the UI that MS ship in their shell and tools. The APIs should still be there. – David Heffernan Jun 27 '12 at 19:46
  • But probably not the supporting `Themes` service, right? – Warren P Jun 27 '12 at 20:13

2 Answers2

13

Ok, I just made a small change to the Vcl.Styles.DateTimePickers unit which is part of the vcl-styles-utils. To fix this issue when the "Windows Classic" theme is active.

Use this style hook in this way

uses
  Vcl.Styles,
  Vcl.Themes,
  Vcl.Styles.DateTimePickers;

initialization
 TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TDateTimePickerStyleHookFix);

And this will be the result.

enter image description here

RRUZ
  • 134,889
  • 20
  • 356
  • 483
1

I can confirm that when I install Desktop Experience, enable Themes and start the Themes service, this glitch goes away.

Okay here's my workaround code for now:

function DetectWin7Or2008R2ClassicTheme:Boolean;
begin

   if  ( Win32MajorVersion>=6 ) then
      result := (not Themes.ThemeServices.ThemesEnabled) // and IsServerOs
   else
      result := false;


end;


// main form initialization section:


initialization
 if DetectWin7Or2008R2ClassicTheme then
 TStyleManager.Engine.RegisterStyleHook(TDateTimePicker, TStyleHook); {no theme!}
end.

It's clearly a wild corner-case. I expect to find more, and I'll come back and update this question when I find what else breaks on Windows Server 2008R2 or Windows 7, when the theme service is not running, which is what happens when you pick "Windows Classic Theme" on Win7, also.

Warren P
  • 65,725
  • 40
  • 181
  • 316