delphi 动态绑定代码都某个控件

delphi 动态绑定代码都某个控件

http://docwiki.embarcadero.com/CodeExamples/Berlin/en/Rtti.TRttiType_(Delphi)
Button16
第一次是绑定代码,第二次就是执行

procedure TForm2.Button16Click(Sender: TObject);
var
aMethod:tMethod;
begin
aMethod.Code:=self.MethodAddress('Button1Click');
aMethod.Data:=self;
TButton(self.FindComponent('Button16')).OnClick := TNotifyEvent(aMethod);
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
  showmessage('hello');
end;

 TButton(self.FindComponent('Button16')).OnClick := TNotifyEvent(aMethod);

这个要强制转换,

改为rtti属性设置赋值。

原文地址:https://www.cnblogs.com/cb168/p/6683337.html