Fixing a FireMonkey TCheckBox/TAction bug

Try this:

  • Create a new FireMonkey HD application, before adding a check box and an action list to the form.
  • Double click the action list and add an action to it; set the action’s AutoCheck property to True.
  • Assign the action just created to the check box’s Action property.
  • Double click the form to create a handler for its OnCreate event. In the handler, set the action’s DisableIfNoHandler property to False:
procedure TForm1.FormCreate(Sender: TObject);
  Action1.DisableIfNoHandler := False;
  • Run the application; once showing, click the check box. Expected: its checked state is toggled. Actual: nothing happens
  • In fact, toggling the check box does work, however you need to double click the control for this to work. This is patently a bug caused by the IsChecked property setter getting called twice in the course of a single mouse click

To fix the problem, you can at a pinch create a suitable interposer class. Doing that won’t be very ‘clean’ however because the IsChecked property setter isn’t virtual, so do this instead:

  • Take a copy of FMX.Controls.pas, add it to your project, and open it up.
  • Find your way to the implementation of TCheckBox.MouseUp.
  • Ignoring the reams of ‘Live’Bindings support code, add a check for IsCheckedStored in front of IsChecked being toggled:
if IsCheckedStored then IsChecked := not IsChecked;

Rebuild the application, and the bug should be fixed.

8 thoughts on “Fixing a FireMonkey TCheckBox/TAction bug

    • Yes, though arguably setting DisableIfNoHandler to False shouldn’t be necessary in the first place, since conceptually, an action with an AutoCheck property set to True *does* have a ‘handler’ – it’s just built into the action itself.

    • To be honest, in this particular case, being reminded of the LiveBindings crap despoiling core FMX units was much more irritating than the actual bug, which took me less time to fix than write the blog post to describe it. Can anyone – including the LB developers themselves – honestly say mixing DB controls code in the code for the core controls themselves is a good idea?

    • For XE3 it will be in something like C:\Program Files\Embarcadero\RAD Studio\10.0\source\fmx. If you only have Starter you would be out of luck though, as that edition doesn’t come with library source code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s