Recent

Author Topic: Prevent firing OnClick event on TSpeedButton  (Read 906 times)

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Prevent firing OnClick event on TSpeedButton
« on: December 29, 2020, 10:24:40 am »
Hi,

I have a TSpeedButton on my form to visually give a user feedback whenever the state changes. An attached OnClick event triggers actions whenever I click on the button.

However, for a particular case, I need that the OnClick does NOT fire when I programmatically change the Down property of the TSpeedButton.

In Delphi, I read that you can use for example TSpeedButton.ClicksDisabled but did not find a similar property in LCL.

I could set the OnClick to NIL and restore it afterwards, but is there a more elegant solution ?

Best regards,
Romain

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: Prevent firing OnClick event on TSpeedButton
« Reply #1 on: December 29, 2020, 10:38:31 am »
TSpeedButton.Enabled := false. Then to restore TSpeedButton.Enabled := true.
This approach has the added benefit that the user can see that the button is not available during processing.
« Last Edit: December 29, 2020, 10:40:52 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Prevent firing OnClick event on TSpeedButton
« Reply #2 on: December 29, 2020, 10:43:02 am »
I cannot reproduce this behaviour (Win 10, Laz 2.0.10/FPC 3.2.0, and Laz trunk/FPC3.2.0): the Speedbutton.OnClick fires only when I physically click on the button, when I toggle the Down state it does not fire.

What are your Laz/FPC versions? Which OS/widgetset?

Thaddy

  • Hero Member
  • *****
  • Posts: 14393
  • Sensorship about opinions does not belong here.
Re: Prevent firing OnClick event on TSpeedButton
« Reply #3 on: December 29, 2020, 10:56:57 am »
I think that what he means that during the processing of the programmatic Down property the button should not fire events. This should be working with my suggestion.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

rpetges

  • Jr. Member
  • **
  • Posts: 96
    • Attribute Changer Website
Re: Prevent firing OnClick event on TSpeedButton
« Reply #4 on: December 29, 2020, 11:50:16 am »
The TSpeedButton.Enabled property did the trick  :)

Many thanks to you all.

jamie

  • Hero Member
  • *****
  • Posts: 6133
Re: Prevent firing OnClick event on TSpeedButton
« Reply #5 on: December 29, 2020, 01:44:01 pm »
I just tried that with and old 2.0.4,2.0.8, 10 and it does not fire the event when toggling the down property via code

I haven't tried the trunk yet but I am sure it also works there , too..


P.s.
  Just tried the trunk , it works there also..

 I will say however I don't like the Themes drawing in windows, when button is in the down state its only a slight differences in shads of blue over here, kind of hard to discern the difference..
 
 This is most likely why I implement the Paint handler for the speed buttons to give it a new bevel look and stay away from the themes drawing.
« Last Edit: December 29, 2020, 01:54:56 pm by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018