14

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.

Peter Turner
  • 11,199
  • 10
  • 68
  • 109

11 Answers11

19

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).

Roman Ganz
  • 1,615
  • 1
  • 20
  • 27
15

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.

Nasreddine Galfout
  • 2,550
  • 2
  • 18
  • 36
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • Like a perfect answer should be. Developers are very lazy these days. – user30478 Feb 10 '19 at 07:29
  • If you read the Delphi documentation and any number of books on the subject, this is how it's done. Has been since Delphi 1. (Except the GroupIndex can be any value that's NOT used by any other button GroupIndex value; that button needs a unique number.) – David Schwartz Jul 04 '23 at 01:22
2

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
X-Ray
  • 2,816
  • 1
  • 37
  • 66
2

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!!

Jeff Yates
  • 61,417
  • 20
  • 137
  • 189
kevin
  • 21
  • 1
1

Hm, strange, I remember using this quite a few times with success. Perhaps you should try playing with the SpeedButton's Down property? I don't think it toggles automatically when you click it --- you should explicitly toggle Down, I guess...

[edit: replaced Checked with Down --- TSpeedButton doesn't have a Checked property, sorry!]

onnodb
  • 5,241
  • 1
  • 32
  • 41
1

The trick is to set the GroupIndex to a unique value and set AllowAllUp to true. If you forget the first, it will not stay down, if you forget the second, it will not stay up, once it has been down.

Thomas Mueller
  • 282
  • 5
  • 8
1

GroupIndex groups the buttons. Only one buttons in the group may be active. All of them needs to have the same index higher than 0.

AllowAllUp allows to switch button down and up, when it is clicked 2 times in a row.

Jacek Krawczyk
  • 2,083
  • 1
  • 19
  • 25
0

Set AllowAllup to true, and Down to false.

Then in OnClick event:

....
btn.AllowAllUp := not btn.AllowAllUp;
btn.Down       := not btn.Down;
....
Nasreddine Galfout
  • 2,550
  • 2
  • 18
  • 36
MacGyver
  • 2,983
  • 1
  • 17
  • 14
0

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;
Mark Patterson
  • 417
  • 2
  • 6
  • 15
-1

I was searching for a solution for my problem and I think this is kind of the same one. I wanted to make a SpeedButton toggle the up and down state just like a switch, and I managed this by setting the properties:

AllowAllUp := True; 
GroupIndex := 1;

Then in the OnClick event of the button I wrote:

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  if( SpeedButton1.AllowAllUp ) then 
  begin 
    SpeedButton1.AllowAllUp := False; 
    SpeedButton1.Down := True; 
  end else 
  begin 
    SpeedButton1.AllowAllUp := True; 
    SpeedButton1.Down := False; 
  end; 
end;

This toggles the button down when it's clicked and up when it's clicked again.

Hope it'll be of any help

Nasreddine Galfout
  • 2,550
  • 2
  • 18
  • 36
-1

Set AllowAllUp to True.

Set GroupIndex to non 0.

To keep it all in the OnClick, try

 with Speedbutton1 do
 begin
      if tag = 1 then tag := 0 else tag := 1;
      down := (tag = 1);
 end;
Steve Graham
  • 114
  • 2
  • 13