大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
  新随笔  :: 联系 :: 订阅 订阅  :: 管理

关于class produre

Posted on 2013-10-21 13:15  大悟还俗_2  阅读(249)  评论(0编辑  收藏  举报
很好理解
type
    TMessageHandler = class     //使得回车消息转换成Tab消息
      class procedure AppMessage(var Msg:TMsg;var Handled:Boolean);
end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
class procedure TMessageHandler.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if Msg.message=WM_KEYDOWN then
    if (Msg.wParam=VK_RETURN ) and
      (
        (Screen.ActiveForm.ActiveControl is TEdit) or               
        (Screen.ActiveForm.ActiveControl is TComboBox) or
        (Screen.ActiveForm.ActiveControl is TCheckBox) or
        (Screen.ActiveForm.ActiveControl is TRadioButton)
              //可以添加需要的控件
      )
    then
    begin
      Msg.wParam:=VK_TAB;
    end
    else if (Msg.wParam=VK_RETURN) and
      (
       (Screen.ActiveForm.ActiveControl is TDBGrid)
      )
    then
    begin
{      with Screen.ActiveForm.ActiveControl do
      begin
        if Selectedindex<(FieldCount-1) then
          Selectedindex:=Selectedindex+1// 移动到下一字段
        else
          Selectedindex:=0;
      end;}
    end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage:=TMessageHandler.AppMessage;
end;
View Code