Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/VCL/Styles    [ Add a report in this area ]  
Report #:  103962   Status: Closed
Disabling a button from its OnClick handler fails to update the buttons's visual appearance
Project:  Delphi Build #:  16.0.4429.46931
Version:    16.4 Submitted By:   David Heffernan
Report Type:  Crash / Data loss / Total failure Date Reported:  3/6/2012 4:27:36 AM
Severity:    Critical / Show Stopper Last Updated: 9/5/2012 7:57:23 PM
Platform:    All versions Internal Tracking #:   26402
Resolution: Fixed (Resolution Comments) Resolved in Build: : 17.0.4625.53395
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 2
Description
When using VCL styles, setting the Enabled property of a TButton to False from that button's OnClick handler fails to update the button's visual appearance.

The button is disabled, it can not be clicked.  However it still looks like it is enabled.  Setting a the Enabled property of a different button (i.e. not the button whose OnClick handler is running) does modify the visuals.
Steps to Reproduce:
Reproduce the problem with the attached project.

The erroneous code is in the Paint method of  TButtonStyleHook:

if FPressed then
  Details := StyleServices.GetElementDetails(tbPushButtonPressed)
else if MouseInControl  then //this condition is triggered even if the button is disabled
  Details := StyleServices.GetElementDetails(tbPushButtonHot)
else if Focused then //this condition is triggered even if the button is disabled
  Details := StyleServices.GetElementDetails(tbPushButtonDefaulted)
else if Control.Enabled then
  Details := StyleServices.GetElementDetails(tbPushButtonNormal)
else
  Details := StyleServices.GetElementDetails(tbPushButtonDisabled);


This code should read:

if not Control.Enabled then
  Details := StyleServices.GetElementDetails(tbPushButtonDisabled);
else if FPressed then
  Details := StyleServices.GetElementDetails(tbPushButtonPressed)
else if MouseInControl then
  Details := StyleServices.GetElementDetails(tbPushButtonHot)
else if Focused then
  Details := StyleServices.GetElementDetails(tbPushButtonDefaulted)
else
  Details := StyleServices.GetElementDetails(tbPushButtonNormal)
Workarounds
If the button's window handle is recreated this is sufficient to produce the correct visuals:

    Button1.Perform(CM_RECREATEWND, 0, 0);
Attachment
VclStylesButtonEnabled.zip
Comments

Tomohiro Takahashi at 4/3/2012 7:51:11 PM -
This report was opened with valid Internal Tracking Number.
Thanks.

Server Response from: ETNACODE01