2008-10-08 3 views
3

TSpeedButton이 눌려 졌을 때 수행하고 싶고, 같은 버튼이 "눌려지지 않은"상태 일 때 수행하고 싶은 액션이 하나 있습니다. 나는 onunpress 이벤트가 없다는 것을 알고 있지만, 다른 버튼을 눌렀을 때 실행할 액션을 얻는 쉬운 방법이 있습니까?델파이의 자동 체크되지 않은 버튼에 대한 액션 실행

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

너무 지나치게 복잡해 보입니다.

답변

5

언 프레스는 없지만 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; 
5

, 난 당신이 같은 그룹의 groupIndex로 <> 0 있지만 다른 버튼으로 speedbutton를 사용하는 가정, 또는 적어도 RadioButtons를 (AllowAllUp을 참)로 작동하지 않습니다.

버튼을 누르기위한 onClick 이벤트는 1 개 뿐이지 만 수행 할 작업은 GroupIndex가있는 경우 버튼의 상태에 따라 다릅니다.
따라서 onClick 처리기가 시작되기 전에 Down이 업데이트되므로 onClick 이벤트 처리기에서 Down being False를 테스트해야합니다.

는 예 :

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

@Francois,이 경우, 발신자 작용하므로 TSpeedButton 같은 송신기는 예외를 제기한다. –

관련 문제