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

后端 未结 11 1969
既然无缘
既然无缘 2021-01-04 12:13

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\

相关标签:
11条回答
  • 2021-01-04 12:56

    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;
    
    0 讨论(0)
  • 2021-01-04 13:01

    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.

    0 讨论(0)
  • 2021-01-04 13:01

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

    0 讨论(0)
  • 2021-01-04 13:01

    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.

    0 讨论(0)
  • 2021-01-04 13:01

    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;
    
    0 讨论(0)
提交回复
热议问题