我建立一个组建
TActiveButton = class(TCustomPanel)
..........
  protected
    //覆盖基类的MouseDown,捕获鼠标消息
    procedure MouseDown(Button:TMouseButton;Shift:TShiftState;X,Y:Integer);override;  published
    property OnMouseDown;
..........protected里的MouseDown事件和publish的OnMouseDown有什么关系呢?
当OnMouseDown事件发生后是怎么关联MouseDown函数的的呢? OnMouseDown代码里面没有关联MouseDown啊
基类TCustomPanel好像也只有OnMouseDown没有MouseDown这个过程```
请高手答疑

解决方案 »

  1.   

    一代代追踪下去就会看到某一级父类会有明确的定义吧
      TMEdt = class(TPanel)
      private
        FOnMouseDown: TMouseEvent;
        procedure SetOnMouseDown(const Value: TMouseEvent);
        protected
        procedure MouseDown(Button:TMouseButton;Shift:TShiftState;X,Y:Integer);override;
        published
        property OnMouseDown: TMouseEvent read FOnMouseDown write SetOnMouseDown;
        end;{ TMEdt }procedure TMEdt.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
      Y: Integer);
    begin
      inherited;
      Self.Caption := FormatDatetime('hh:nn:ss.zzz', Now);
    end;procedure TMEdt.SetOnMouseDown(const Value: TMouseEvent);
    begin
      FOnMouseDown := Value;
    end;
      

  2.   

    也就是说这个事件是windows消息事件,当接收到这个消息就会执行MouseDown 方法吧???
      

  3.   

    我也糊涂了,不想再考虑了,等楼下其他人说吧这是TControl的MouseDown方法procedure TControl.MouseDown(Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X, Y);
    end;
      

  4.   

    这部分代码要看controls单元中
    Tcontrol类的定义    property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
    OnMouseDown 和 FOnMouseDown绑定了继续
    procedure TControl.MouseDown(Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, X, Y);
    end;
    MouseDown 就是调用FOnMouseDown ,也就是OnMouseDown;
    再继续
    procedure TControl.DoMouseDown(var Message: TWMMouse; Button: TMouseButton;
      Shift: TShiftState);
    begin
      if not (csNoStdEvents in ControlStyle) then
        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;
    DoMouseDown函数调用MouseDown
    再再继续procedure TControl.WMLButtonDown(var Message: TWMLButtonDown);
    begin
      SendCancelMode(Self);
      inherited;
      if csCaptureMouse in ControlStyle then MouseCapture := True; 
      if csClickEvents in ControlStyle then Include(FControlState, csClicked);
      DoMouseDown(Message, mbLeft, []);
    end;
    在鼠标左键消息中调用 DoMouseDown。还有WMLButtonDblClk、 WMRButtonDown、WMRButtonDblClk、 WMMButtonDown、WMMButtonDblClk在所有鼠标按下消息处理中都调用DoMouseDown总结从鼠标消息开始(WMLButtonDown、WMLButtonDblClk、 WMRButtonDown、WMRButtonDblClk、 WMMButtonDown、WMMButtonDblClk)----》DoMouseDown---》MouseDown----》FOnMouseDown(也就是OnMouseDown)