自定义标题栏组件有有关问题,大家进来了看看,见源码

自定义标题栏组件有问题,大家进来了看看,见源码
unit   Unit_CaptionBar;

interface

uses
    SysUtils,Windows,Forms,Classes,Controls,ComCtrls,StdCtrls,ExtCtrls,Messages;

type
    TCaptionBar=class(TCustomPanel)
    private
        FOnMouseDown:   TMouseEvent;
        procedure   DoMouseDown(var   Message:   TWMMouse;   Button:   TMouseButton;
        Shift:   TShiftState);
        procedure   WMLButtonDown(var   Message:   TWMLButtonDown);   message   WM_LBUTTONDOWN;
    protected
        procedure   Notification(AComponent:TComponent;Operation:TOperation);   override;
        procedure   MouseDown(Button:   TMouseButton;   Shift:   TShiftState;
        X,   Y:   Integer);   override;
    public
        constructor   Create(AOwner:TComponent);override;
        property   OnMouseDown:   TMouseEvent   read   FOnMouseDown   write   FOnMouseDown;
    end;
{   TCaptionBar   }

procedure   Register;

implementation

procedure   Register;
begin
    RegisterComponents( 'CaptionBar ',[TCaptionBar]);
end;

constructor   TCaptionBar.Create(AOwner:   TComponent);
begin
    inherited;
    Top:=0;
    Align:=alTop;
    Height:=19;
end;

procedure   TCaptionBar.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;

procedure   TCaptionBar.MouseDown(Button:   TMouseButton;   Shift:   TShiftState;
    X,   Y:   Integer);
begin
    inherited;
    if   (Self.Owner   is   TForm)   then
    begin
        ReleaseCapture;
        (Self.Owner   as   TForm).Perform(WM_SYSCOMMAND,$F012,0);
    end;
end;

procedure   TCaptionBar.Notification(AComponent:   TComponent;
    Operation:   TOperation);
var
    AForm:TForm;
begin
    inherited;
    if   not   (csDesigning   in   ComponentState)   then
    begin
        //这段代码有问题,大家帮帮忙啊,关闭窗体时报错
        if   (Self.Owner   is   TForm)   then
        begin
            AForm:=(Self.Owner   as   TForm);