Perform action for automatically removed button in Delphi

I have one action that I want to perform when the TSpeedButton button is pressed, and another that I want to perform when the same button is not pressed. I know there is no onunpress event, but is there any simple way to execute the action when another button is pressed?

procedure ActionName.ActionNameExecute(Sender: TObject);
begin
  PreviousActionName.execute(Sender);
  //
end;

Seems too awkward.

+3
source share
2 answers

There is no unpress, but you can request the Down property.

Some dirty videos were taken in the example, but it works for both action and OnClick.

procedure Form1.ActionExecute(Sender: TObject);
var
  sb : TSpeedButton;
begin
  if Sender is TSpeedButton then
    sb := TSpeedButton(Sender)
  else if (Sender is TAction) and (TAction(Sender).ActionComponent is TSpeedButton) then
    sb := TSpeedButton(TAction(Sender).ActionComponent)
  else 
    sb := nil;

  if sb=nil then
    DoNormalAction(Sender)
  else if sb.Down then
    DoDownAction(sb)
  else 
    DoUpAction(sb);
end;
+5
source

, , , GroupIndex < > 0, , , , RadioButtons (AllowAllUp True).

onClick , , , GroupIndex.
, , Down False onClick, Down , onClick .

:

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  with Sender as TSpeedButton do
  begin
    if Down then
      showmessage('pressing')
    else
      showmessage('unpressing');
  end;
end;
+5

Source: https://habr.com/ru/post/1698048/


All Articles