当按下 TSpeedButton 时,我希望执行一个操作,当“未按下”相同的按钮时,我希望执行另一个操作。我知道没有 onunpress 事件,但是否有任何简单的方法让我在按下不同的按钮时执行操作?
procedure ActionName.ActionNameExecute(Sender: TObject);
begin
PreviousActionName.execute(Sender);
//
end;
看起来太笨重了。
虽然没有“未压缩”的属性,但您可以查询Down属性。
这个例子需要进行一些不太干净的转换,但它适用于操作和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;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
with Sender as TSpeedButton do
begin
if Down then
showmessage('pressing')
else
showmessage('unpressing');
end;
end;