请问在用DELPHI创建DLL文件的时候,要想动态创建一个TTimer控件,并写事件OnTimer,该如何做?library MyDll;uses
 Dialogs,ExtCtrls;Var MyTimer:TTimer;procedure MyTimerOnTimer(Sender:TObject);
begin
 ShowMessage('aa');
end;begin
 MyTimer:=TTimer.Create(nil);
 MyTimer.OnTimer := MyTimerOnTimer; // 编译不过. 
                // Incompatible types: 'method pointer and regular procedure'
end;
end.请问是什么错误?

解决方案 »

  1.   

    随便弄一个class出来,然后把procedure MyTimerOnTimer做为那个class的member function就是了。
      

  2.   

    你把代码改为这样:
    ============================
    library MyDll;uses
     Dialogs,ExtCtrls;Var MyTimer:TTimer;procedure MyTimerTimer(Sender:TObject);
    begin
     ShowMessage('aa');
    end;begin
     MyTimer:=TTimer.Create(nil);
     MyTimer.OnTimer := MyTimerTimer; // 编译不过. 
                    // Incompatible types: 'method pointer and regular procedure'
    end;
    end.
      

  3.   

    问题的关键是:
    Timer的OnTimer()事件的原形你要搞清楚!
    =======================================
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      ... ...
    end;
      

  4.   

    >随便弄一个class出来,然后把procedure MyTimerOnTimer做为那个class的member function就>是了。
    能举例吗? 谢谢.> to : lgqTiger(把酒论程序__尽在笑谈间) 
    你说要改的代码和我上面的一样啊? 不是吗?
      

  5.   

    library MyDll;uses
      Forms,Dialogs,ExtCtrls;
    type
      TForm1 = class(TForm)
      private
      procedure MyTimerOnTimer(Sender:TObject);
         { Private declarations }
      public
        { Public declarations }
    end;var MyTimer:TTimer;procedure TForm1.MyTimerOnTimer(Sender:TObject);
    begin
      ShowMessage('aa');
    end;begin
      MyTimer:=TTimer.Create(nil);
      MyTimer.OnTimer:=MyTimerOnTimer; //Undeclared identifier:'MyTimerOnTimer'  
                                       //一样编译不过啊,如果是在Form里面,在FomrCreate事
                                       //件中写这两句代码就能运行,但在DLL里为什么不可以?
    end.这个问题应该不难吧,新年论坛人少吗? 
    现在一些DLL木马是不是也是在DLL里自定义TCPServer或是TCPClient,然后写它们的相关代码的??
      

  6.   

    关键问题是delphi中的过程和类中的方法还是有些区别的,把你那个form移去(这里不需要的)
    library MyDll;uses
      Dialogs,ExtCtrls;
    type
      Tmyclass = class
      private
       procedure MyTimerOnTimer(Sender:TObject);
      public
    end;var MyTimer:TTimer;
        myclass:TMyClass;procedure Tmyclass.MyTimerOnTimer(Sender:TObject);
    begin
      ShowMessage('aa');
    end;begin
      MyTimer:=TTimer.Create(nil);
      MyClass:=TMyClass.Create;
      MyTimer.OnTimer:=myclass.MyTimerOnTimer;
    end.
      

  7.   

    library MyDll;uses
     Dialogs,ExtCtrls;Var MyTimer:TTimer;procedure MyTimerOnTimer(Sender:TObject);
    begin
     ShowMessage('aa');
    end;begin
     MyTimer:=TTimer.Create(nil);
     MyTimer.OnTimer := @MyTimerOnTimer; // 前面加一个@
    end;
    end.