第一步:
      procedure TControl.WMLButtonDown(var Message: TWMLButtonDown); 
    begin 
    SendCancelMode(Self); //这一步?是取消模态窗口模式吧,我想问下放在这里有什么用?为什么要取消
    inherited; 
    if csCaptureMouse in ControlStyle then  //判断1
       MouseCapture := True; 
    if csClickEvents in ControlStyle then  //判断2 我查了一下,ControlStyle里面包含了这两个状态为什么这里面还判断是否包含呢?
      Include(FControlState, csClicked); //这里面的Include是什么意思?
     DoMouseDown(Message, mbLeft, []); 
   end; 
第二步:
     procedure TControl.DoMouseDown(var Message: TWMMouse; Button: TMouseButton;
  Shift: TShiftState);
begin
  if not (csNoStdEvents in ControlStyle) then //还是这个ControlStyle是否在别的地方删除过,这里面也需要判断呢?
    with Message do
      if (Width > 32768) or (Height > 32768) then
        with CalcCursorPos do
          MouseDown(Button, KeysToShiftState(Keys) + Shift, X, Y)
      else
        MouseDown(Button, KeysToShiftState(Keys) + Shift, Message.XPos, Message.YPos);
end;麻烦懂的人,花一点时间帮我解释一下,我真的很想知道,看了一天了,没看明白,谢谢

解决方案 »

  1.   

    1、SendCancelMode(Self): trace下去你會發現調用的customform.sendcancelmode;然后perform消息cm_CancelMode。目的是,使得form上的activecontrol得到通知,是否要取消當前的狀態。比如combobox當前處于下拉狀態,若你點擊了其他地方,combobox就會收到此類消息。2、if csClickEvents in ControlStyle then  : ControlStyle 是可以被改的,這判斷控件本身是否接受click事件;3、Include(FControlState, csClicked); : 表示當前控件處于被click狀態,此元素,在lbuttonup時會被exculde;4、if not (csNoStdEvents in ControlStyle) then: 同第2點原理,判斷是否接受標準事件(鼠標、鍵盤事件)
      

  2.   

    谢谢你,那我想问下ControlStyle这里面的风格值是在哪里被改变的呢?
      

  3.   

    可以任何時候,只要你想,比如不想讓GroupBox1響應click事件:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      GroupBox1.ControlStyle := GroupBox1.ControlStyle - [csClickEvents];
    end;
      

  4.   

    恩,明白了,呵呵,谢谢,真想有人带带我,一直在自学,真想好好把DELPHI学会,理解其大概个本质,虽然公司项目还没用上,但喜欢,哈哈
      

  5.   

    你都懂得一下子去看delphi vcl源碼,學起來應該很快。