我从TStringGrid继承了一个TMyStringGrid组件,现在想修改OnKeyPress方法,请问他的消息是什么,怎么才能修改

解决方案 »

  1.   

    override KeyPress(var Key: Char)
      

  2.   

    祖先类TCustomGrid有此方法,重载即可
      

  3.   

    OnKeyPress是个事件,是不能重载的。只能重载keypress方法。
    代码如下
    type
      TMyStringGrid=class(TStringGrid)
      protected
        procedure KeyPress(var Key: Char); override;
      end;
    实现部分
    procedure TMyStringGrid.KeyPress(var Key: Char);
    begin
      //如果什么也不做,注释掉即可
      //inherited KeyPress(Key);
      //可添加自己的代码
      //....
    end;
      

  4.   

    protected中重载procedure KeyPress(var Key: Char); override;方法,其存在于TWinControl中