您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

TMethod的妙用:解决动态创建的组件的事件赋值问题

时间:2011/9/3 15:38:31 点击:

  核心提示:program Test;usesWindows,SysUtils,ExtCtrls,Classes,Forms;vartimer1:TTimer; Method:TMethod;procedure...
program Test;

uses
  Windows,
  SysUtils,
  ExtCtrls,
  Classes,
  Forms;

var
  timer1:TTimer; Method:TMethod;

procedure Timer1Timer(Self, Sender: TObject);  // 注意要比类下面的方法多一个Self参数
// 在类中声明是隐含了的, 改为外部声明就必须包含这个4 Bytes的用来传递TMethod.Data的参数
begin
  MessageBox(0, 'aa', 'bb', 0);
end;

begin
   timer1:=TTimer.Create(nil);
   timer1.Interval:=3000;
   Method.Data := nil;
   Method.Code := @Timer1Timer;
   timer1.OnTimer:= TNotifyEvent(Method);
   while True do Application.ProcessMessages;
end.

作者:LY 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号