动态创建的控件,如何把事件写在一个公共的unit里面?

解决方案 »

  1.   

    可以通过TMethod的处理
    Unit中写:
    procedure Timer1Timer(Sender: TObject);
    begin
      MessageBox(0, 'aa', 'bb', 0);
    end;调用是
    var
      Method:TMethod;
    begin
       Method.Data := nil;
       Method.Code := @Timer1Timer;
       timer1.OnTimer:= TNotifyEvent(Method);
    end.http://lysoft.7u7.net
      

  2.   

    如果我的动态创建一个button,想把它的onclick写到一个公共的单元的里,怎么写呀?
      

  3.   

    不行,,
    [Error] Unit1.pas(43): Incompatible types: 'method pointer and regular procedure'
      

  4.   

    _objmi.Caption := 'ddd';
    _objmi.OnClick:=addpoppro;在一个公共的unit里
    Procedure addpoppro(Sender: TObject);