Pet*_*ner 3 delphi button taction
当我按下TSpeedButton时我想要执行一个动作,而当同一个按钮被"未按下"时我想要执行另一个动作.我知道没有onunpress事件,但有什么简单的方法可以让我在按下不同的按钮时执行操作?
procedure ActionName.ActionNameExecute(Sender: TObject);
begin
PreviousActionName.execute(Sender);
//
end;
Run Code Online (Sandbox Code Playgroud)
看起来太笨重了.
没有unpress,但您可以查询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;
Run Code Online (Sandbox Code Playgroud)
根据您的描述,我想您使用的是一个GroupIndex <> 0的快速按钮,但同一组中没有其他按钮,或者至少不能用作RadioButtons(AllowAllUp True).
您只有1个onClick事件用于按下按钮,但如果它具有GroupIndex,则该操作取决于按钮的状态.
因此,您必须在onClick事件处理程序中测试Down为False,因为在onClick处理程序被触发之前更新了Down.
例如:
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
with Sender as TSpeedButton do
begin
if Down then
showmessage('pressing')
else
showmessage('unpressing');
end;
end;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2855 次 |
| 最近记录: |