是这样的:
我要给form1添加一个OoMouseDown 事件,比如:form1.OnMouseDown := MyMouseDown; //但这样报错了。请问MyMouseDown事件应该怎么写?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private
        { Private declarations }    procedure MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);  public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      onMouseDown :=  mouseDown;
    end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    //
    end;end.
      

  2.   

    同意idilent
    MyMouseDown应该和OnMouseDown是同一 Tprocedure 类型
      

  3.   

    OnMouseDown是TMouseEvent类型的,这样行吗?
      

  4.   

    打开Tform的创建代码看看就知道了。
      

  5.   

    你将procedure onmonusedown(sender:Tobject)的声明放在什么地方,
    应该在Tform1的定义中
    type
      TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    //此处放MyOnMouseDown声明
      private
        { Private declarations }
       //或此处放MyOnMouseDown声明
      public
      //或此处放MyOnMouseDown声明
        { Public declarations }
      end;
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)    procedure onmonusedown();  private
        { Private declarations }  public
        { Public declarations }
      end;var
      Form1: TForm1;implementation
    {$R *.dfm}procedure TForm1.onmonusedown();
    begin
        事件驱动!  
    end;procedure TForm1.mouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    //
    end;end.
      

  7.   

    其实就是动态创建一个控件然后给该对象的事件定义一个函数。该函数的参数与onmousedown的参数相同,/////////////////////////////////////////////////////////
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}end.
    //////////////////////////////////////////////////////////////
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm2 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
       // myForm1: TForm1;
       procedure MyMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      public
        { Public declarations }
      end;var
      Form2: TForm2;  //myForm1: Form1;implementationuses Unit1;{$R *.dfm}procedure TForm2.MyMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
    begin
      ShowMessage('ok');
    end;procedure TForm2.Button1Click(Sender: TObject);
    var
      MyForm: TForm1;
    begin
      MyForm := TForm1.Create(nil);
      myForm.OnMouseDown := Form2.MyMouseDown;
      MyForm.ShowModal;
    end;end.
    /////////////////////////////////////////////////////
    主窗体为form2,form1是手动创建的