我定义了一个右键菜单一个DBGrid一个Query
PopupMenu中定义两个事件即继承了两个TMenultem
一个为N1,另一个为N2
DBGrid指向右键菜单DBGrid.PopupMenu:= PopupMenu;
在DBGrid的MouseDown事件中定义:
    如果条件为A则N1.Enable := true,N2.Enable := False;
    如果条件为A则N1.Enable := False,N1.Enable := true;
想达到的效果为:在条件A下右键菜单弹出时N1可用,N2不可用;
                在条件B下右键菜单弹出时N2可用,N1不可用;

解决方案 »

  1.   

    结果出现以下情况:
        在条件A下第一次弹出时N1可用,N2不可用,第二次弹出时N1可用,N2不可用;
    马上转换为条件B则,第一次弹出时N1可用,N2不可用,
                       第二次弹出时N2可用,N1不可用;
    再转换为条件A则,第一次弹出时N2可用,N1不可用,
                     第二次弹出时N1可用,N2不可用;
    即我所定义的事件滞后一次,也就是说右键菜单先弹出,再做判断,所以判断之后的操作只对下一次弹出的菜单进行了限制,
    如何能在弹出之前进行判断操作呢?????
      

  2.   

    将你的处理过程写到
    PopupMenu的OnPopup事件里
      

  3.   

    PopupMenu的OnPopup事件里
    不支持 Button = mbRight 啊
    我是用他来判断是否右键弹出的
      

  4.   

    把popupmenu的autopopup属性设为false;
    然后在mousedown事件中,判断是否为右键,判断自己的条件,然后再弹出
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin  if (ssright in shift ) then
          if A then 
             begin
                N1.Enable := true;
                N2.Enable := False;
                popupmenu1.popup;         end
          else if B then
             begin
                N2.Enable := true;
                N1.Enable := False;
                popupmenu1.popup;
             end;
    end;