VCLSkin可能存在的一个bug隐患

本文介绍了一种在VCLSkin环境下出现的焦点处理Bug,该Bug发生在使用Tab键切换焦点并在特定控件上按下空格键或字母键时。通过对CMDialogChar消息处理过程的分析与修改,有效解决了地址错误的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

产生bug的情况:     
1, 使用Tab键切换焦点在Button上,按空格键执行按钮事件时    
2, 焦点在RadioButton上,按任意字母时    
bug错误现像:地址错误    

环境: VCLSkin 4.9.1, Win 2003 Ent Sp2, Delphi 7.0   

WinSkinForm.pas中代码段:    
//fixed by Brian Lowe    
procedure TWinSkinForm.CMDialogChar(var Message: TMessage); //TCMDialogChar    
var    
  Button: TMenubtn;    
  ShiftState: TShiftState;    
  KeyState: TKeyboardState;    
begin    
  OldWndProc(message);    
  if message.result<>0 then exit;    

    GetKeyboardState(KeyState);    
    ShiftState := KeyboardStateToShiftState(KeyState);    
    Button := FindButtonFromAccel(TWMKey(Message).CharCode);    
    if (Button <> nil) and (ShiftState = [ssAlt]) then begin    
        clickbutton(button);    
        Message.Result := 1;    
        done2:=true;    
    end else begin    
       //mdiform mainmenu shortcut    
        if (formstyle=sfsmdichild) then begin    
           if skinmanager.MDIForm.Perform(CM_DIALOGCHAR,    
                  TWMKey(Message).CharCode,TWMKey(Message).KeyData)<>0 then exit;    
        end else if (fform<>application.MainForm) and (not (fsModal in fform.FormState)) then begin //has problem    
             application.MainForm.Perform(CM_DIALOGCHAR,TWMKey(Message).CharCode,TWMKey(Message).KeyData);  [注1]    
        end;    
        message.Result:=0;    
//      OldWndProc(message);    
    end;      
end;    

本想写个示例程序,但新建的示例程序怎么也不出现错误.    
比如幸运的时, 作者在写这部分代码时,有一行注释:mdiform mainmenu shortcut, 现在没时间去追根问底, 对于这一行注释, 猜测这是针对MDI窗口的代码, 所以,有一种情况是:一直在执行[注1]处代码, 为了避免这种隐患, 加一行代码或许更好些(下面代码粗体部分).    

//fixed by Brian Lowe  
procedure TWinSkinForm.CMDialogChar(var Message: TMessage); //TCMDialogChar  
var  
  Button: TMenubtn;  
  ShiftState: TShiftState;  
  KeyState: TKeyboardState;  
begin  
  OldWndProc(message);  
  if message.result<>0 then exit;  

    GetKeyboardState(KeyState);  
    ShiftState := KeyboardStateToShiftState(KeyState);  
    Button := FindButtonFromAccel(TWMKey(Message).CharCode);  
    if (Button <> nil) and (ShiftState = [ssAlt]) then begin  
        clickbutton(button);  
        Message.Result := 1;  
        done2:=true;  
    end else  if (Application.MainForm <> nil) and (Application.MainForm.FormStyle = fsMDIForm) then begin  
      //mdiform mainmenu shortcut  
      if (formstyle=sfsmdichild) then begin  
         if skinmanager.MDIForm.Perform(CM_DIALOGCHAR,  
                TWMKey(Message).CharCode,TWMKey(Message).KeyData)<>0 then exit;  
      end else if (fform<>application.MainForm) and (not (fsModal in fform.FormState)) then begin //has problem  
          application.MainForm.Perform(CM_DIALOGCHAR,TWMKey(Message).CharCode,TWMKey(Message).KeyData);  

      message.Result:=0;  
    end; 
//      OldWndProc(message);  
    e 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值