如果TSpeedButton已经关闭,如何提前退出()

时间:2016-03-07 13:33:41

标签: delphi delphi-xe2

我有两个TSpeedButtonbtn1btn2。它们的属性被设置为它们在一个组中共同作用并且是互斥的,这意味着当按下一个按钮时,另一个按钮会自动被按下:

AllowAllUp = False
GroupIndex = 1
OnClick = onSpeedButtonsClick

我在onSpeedButtonsClick()中有一些代码,根据点击的两个按钮中的哪一个运行一些代码。

我正在尝试做的是,如果btn1当前为Down,并且用户按下此按钮,则不会发生任何事情:

procedure frmMyForm.onSpeedButtonsClick(Sender: TObject);
begin
  { Don't do anything if the clicked button is already currently pressed down. }
  if ((Sender = btn1) and btn1.Down) or
       ((Sender = btn2) and btn2.Down) then
    Exit();

  { ... some other code here that should only run when
    the `Down` state of the buttons changes }
end;

问题是当btn1当前关闭并且用户按下btn2时,Down的{​​{1}}属性设置为btn2 True执行之前,无论如何都onSpeedButtonsClick()

2 个答案:

答案 0 :(得分:2)

我会使用按钮'var canv=document.getElementById("output"); var ctx=canv.getContext("2d"); var canimg=($('img',data)); ctx.drawImage(canimg,10,10); 属性来跟踪所需的状态,例如:

Tag

答案 1 :(得分:1)

只需在表单字段中存储按钮状态,并将其设置在事件处理程序的末尾,如下所示(我使用了位域)

bState := Ord(btn1.Down) or (Ord(btn2.Down) shl 1);

检查:

   if (bState and 1) <> 0 then  
//it would be nicer to use constants like btn1down = 1 instead of magic numbers
      btn1 WAS down before
   if (bState and 2) <> 0 then
      btn2 WAS down before