How to make a Delphi TSpeedButton stay pressed if it's the only one in the group

29,273

Solution 1

I have no D7 here, but in D2006 a Speedbutton stays down if the GroupIndex has a value > 0.

If this is not the behaviour you wish, you can set the Down-Property manually in the OnClick-Eventhandler (make sure, that the GroupIndex is 0).

Solution 2

I just tried that in Delphi 7 (Build 4.453):

  • create new application
  • add TSpeedButton to form
  • set AllowAllUp := true;
  • set GroupIndex := 1;
  • run application

When clicking the button it toggles its down state without any other code needed.

Solution 3

knight_killer is correct. i can tell you it'll work in any version of delphi:

object SpeedButton1: TSpeedButton
  Left = 152
  Top = 384
  Width = 23
  Height = 22
  AllowAllUp = True
  GroupIndex = 99
end

Solution 4

Delphi does the work for you so "don't write ANY CODE".

In the IDE select ALL of your SpeedButtons that you want to operate as a group and then set the whole group's "GroupIndex" to something other than "0" and you are done -- with NO CODE -- NADA!!

Solution 5

To get this to work, you can't just toggle the Down property, because it is always down in the OnClick event. You need to have another value:

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  MyBoolProperty := not MyBoolProperty;
  SpeedButton1.Down := MyBoolProperty;
end;
Share:
29,273
Peter Turner
Author by

Peter Turner

Faithful Catholic - Father of 5, Husband of 1 Programmer of cloudish things from Southern Wisconsin.

Updated on October 26, 2020

Comments

  • Peter Turner
    Peter Turner over 3 years

    I'm not sure why the TSpeedButton has this property but when a TSpeedButton is the only button of a given groupindex, it doesn't stay pressed, whether or not "AllowAllUp" is pressed. Maybe a Jedi control would suffice, but hopefully there's some fix. Any help or anecdotes are appreciated.

    BTW, I'm (still) using Delphi 7, not sure if this is an across the board conundrum.

  • user1798101
    user1798101 over 15 years
    yes, use any GroupIndex you want. But it have to be greater then zero
  • user30478
    user30478 over 5 years
    Like a perfect answer should be. Developers are very lazy these days.