the Handled parameter indicates whether the event handler responded to the message. Set Handled to True if the message has been completely handled, to prevent subsequent processing of the message.
也就是表示处理完了

解决方案 »

  1.   

    你的procedure中定义的一个参数,作为一个判定的开关.
    procedure TForm_OvertimeInput.ApplicationEvents1Message(var Msg: tagMSG;var Handled: Boolean);/////////////////////////
      if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then 
    这判定语句是判定如果传递给本过程的消息(Msg)是从TWinControl类继承下来的具有窗口句柄(Handle)的话那么就执行下面的语句.
    //////////////////
    这段过程好像是DBGrid中还添加了其它的控件,如PopMenu和其它的具有Handl的从TWinControl下继承下来的控件.
    //////////////
    没有菜单的原因是它只在用户选中"GlTime"字段时才出现.多试一下吧.
     if Str_FieldName='G1TIME' then
          begin
            G_FieldNo:=1;
            Pm_OT.Popup(Msg.pt.x,Msg.pt.y);
          end
      

  2.   

    procedure TForm_OvertimeInput.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    Var
      Str_FieldName:String;
    begin
      if (ActiveControl=DBGrid_OVERTIMETABLE)and(msg.message = WM_RBUTTONUP)then //活动的控件与右键;
      begin
        Handled:=True;//处理完毕;
        if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then //是向该控件发送消息;
        begin
          Str_FieldName:=DBGrid_OVERTIMETABLE.SelectedField.FieldName;
                 //得到选定的列名;
          if Str_FieldName='G1TIME' then
          begin //如果是这个东西
            G_FieldNo:=1;
            Pm_OT.Popup(Msg.pt.x,Msg.pt.y); //弹出菜单;
          end
          else ....
    //好象是这样的~~~~~~~
      

  3.   

    我現在仍有2點疑問;
    1.  Handled:=True;  是什麼处理完毕??
    2.  Components[0]  是不是的dbgrid第1列字段呀 ?
      

  4.   

    Handled := True; //确定 消息处理 不由系统处理function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
    var
      Handled: Boolean;
    begin
      Result := False;
      if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
      begin
        Result := True;
        if Msg.Message <> WM_QUIT then
        begin
          Handled := False;
          if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
          if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          begin
            TranslateMessage(Msg);
            DispatchMessage(Msg);
          end;
        end
        else
          FTerminate := True;
      end;
    end;Components[0]; //就是DBGrid上的编辑框
      

  5.   

    to   zswang(伴水):  Handled := True; //确定消息处理 不由系统处理?? 能否說具體一點???  Components[0]; //就是DBGrid上的编辑框, 是不是的dbgrid第1列字段呀 ?
      

  6.   

    你看一下帮助
    1.  Handled:=True; Handled是一个返回值,也就是说你执行完这个实践后,把Handled返回给系统,系统根据Handled的值决定下一步做什么!Handled含义你可以从帮助里查,(我不记得了,不好意思)
    2dbgrid的每一列都是一个类,有自己得句柄,一个字短一般是一个数租。
      

  7.   

    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      Handled := True; //测试这个代码看看//明白了吧
    end;
    其实DBGrid上只有一个编辑框
    如果每一个区都有编辑框
    系统资源不是耗大了吗!
      

  8.   

    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      Handled := True; //测试这个代码看看//明白了吧
    end;
    其实DBGrid上只有一个编辑框
    如果每一个区都有编辑框
    系统资源不是耗大了吗!
      

  9.   

    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      Handled := True; //测试这个代码看看//明白了吧
    end;
    其实DBGrid上只有一个编辑框
    如果每一个区都有编辑框
    系统资源不是耗大了吗!
      

  10.   

    不是列,要知道dbgrid也是又一个个控件,如edit什么组成的,那个(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle 应该和dbgrid1.handle一样吧~~我实在对不对了~~
      

  11.   

    我剛才看了幫助 Handled := True; 是'prevent subsequent processing of the message .'  其意思是不執行後面的代碼,還是不處理後面捕著的事件??DBGrid_OVERTIMETABLE.Components[0]與DBGrid_OVERTIMETABLE.Components[1]有啥區別???
      

  12.   

    我剛才看了幫助 Handled := True; 是'prevent subsequent processing of the message .'  其意思是不執行後面的代碼,還是不處理後面捕著的事件??DBGrid_OVERTIMETABLE.Components[0]與DBGrid_OVERTIMETABLE.Components[1]有啥區別???
      

  13.   

    Carfield 回答的;////////////////////////////////////////
    1.没有特别的意思,只是一个标识而已,即执行到这里时Handled的值为True
    2.你看一下是否有部分控件设定其Parant属性是否设为DBGrid,这句语句的意思是BDGrid下包含的控件数组 Components[0]表示第一个控件.
    你可以试一试下面的语句
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Button1.Parent:=DBGrid1;
    end;
    button是不是跑到DBGrid1里面去了? 
      

  14.   

    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
                              ~~~~~~~~~~~not Handled 不处理TranslateMessage(Msg),DispatchMessage(Msg);
          DBGrid_OVERTIMETABLE.Components[0]
    DBGrid_OVERTIMETABLE.Components[1]
    你说 “0”和“1” 有什么区别
    自己做测试,自己看帮助努力工作中.......................
      

  15.   

    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
          
    if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
            not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
                              ~~~~~~~~~~~not Handled 不处理TranslateMessage(Msg),DispatchMessage(Msg);
          DBGrid_OVERTIMETABLE.Components[0]
    DBGrid_OVERTIMETABLE.Components[1]
    你说 “0”和“1” 有什么区别
    自己做测试,自己看帮助努力工作中.......................
      

  16.   

    正常情况下dbgrid1.ComponentCount上为0的,就是说在它不包含其他控件,但是比如
    var e : TEdit;
    begin
      e := TEdit.Create(form1);
      e.Parent := dbgrid1;
    end;
    那么dbgrid1.ComponentCount=1,而dbgrid1.Components[0].ClassName就是TEdit。
      

  17.   

    正常情况下dbgrid1.ComponentCount上为0的,就是说在它不包含其他控件,但是比如
    var e : TEdit;
    begin
      e := TEdit.Create(form1);
      e.Parent := dbgrid1;
    end;
    那么dbgrid1.ComponentCount=1,而dbgrid1.Components[0].ClassName就是TEdit。
      

  18.   

    有人告訴我說是 windows是層層傳遞消息,像冒泡, Handled:=True點被截獲後,不往上繼續傳了. 對嗎??
      

  19.   

    第二個問題  if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then
      我還是不理解???
      

  20.   

    第二個問題  if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then
      我還是不理解???
      

  21.   

    謝謝大家. 第二個問題  if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then
      我還是不理解???
      

  22.   

    就是说如果DBGrid_OVERTIMETABLE的第一个组件是TWinControl,且DBGrid_OVERTIMETABLE.Components[0]的句柄和接收到这个消息的组件的句柄相同则作下边的事;
      

  23.   

    handled是程序中自己定义或继承下来的一个参数,它应是和).handle 联系使用的。if Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle then  dbgrid.components[0]是指dbgrid1所对应的第一字段所在列。整段程序的意思是当你的鼠标右击在该dbgrid的第一字段所地列时且其字段名为G1TIME时,设置G_FieldNo:=1;且在(x,y)处显示弹出菜单。
      

  24.   

    第二個問題   就 zswang(伴水)的回答正確; 
     Components[0]; //就是DBGrid上的编辑框,其实DBGrid上只有一个编辑框
    程序中DBGrid顯示8個字段,我測試代碼的情況是;
       @(1)只在任何一個字段上點鼠標右鍵,執行到
    Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle 
    其值為False,
       @(2)在任何一個字段上雙擊鼠標,使此字段為編輯狀態,再點鼠標右鍵時Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle 
    其值為true, 才可能有上下文菜單但我又有疑問;
      對@(1) (ActiveControl=DBGrid_OVERTIMETABLE) and (msg.message = WM_RBUTTONUP) 為true ,不就是說
    msg的句柄是DBGrid_OVERTIMETABLE的句柄嗎 ??    既然如此的話 Msg.hwnd=(DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle 
    其值為什麼不是true呢 ??
      

  25.   

    DBGrid_OVERTIMETABLE.Components[0] <> DBGrid_OVERTIMETABLE
      

  26.   

    (DBGrid_OVERTIMETABLE.Components[0] as TWinControl).handle 是在dbgrid上的那个编辑框吧的句柄;(ActiveControl=DBGrid_OVERTIMETABLE) and (msg.message = WM_RBUTTONUP) 為true 指的是当前form上处于“活动”的控件是grid并且消息是鼠标右键;
    在你的程序中,这是最外层的条件,只有它满足以后才考虑其他的条件;
      

  27.   

    thing you  我明白了.