如何通过新的RTTI设置事件处理程序?[D2010] [英] How to set event handlers via new RTTI? [D2010]

查看:79
本文介绍了如何通过新的RTTI设置事件处理程序?[D2010]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用新的RTTI模块时,我找不到使用新实用程序设置事件处理程序的方法.尝试这样的事情:

Playing with new RTTI module, I couldn't find a way to set an event handler with the new utilities. Trying something like this:

LProp := TRttiContext.Create.GetType(Form1.ClassInfo).AsInstance.GetProperty('OnClick');
LProp.SetValue(Form1, {a TValue!}); 

SetValue需要传递一个TValue,但是我还没有找到一种通过TValue表示TMethod的方法.有任何评论吗?

SetValue needs a TValue passed but I've yet to find a way to represent a TMethod via a TValue. Any comments?

ps.还有一个附带的问题..似乎在RTTI变量前面加上"L"是一种惯例(而且对于一个不错的IMO,元代码很快就变成了难题).但是它实际上代表什么呢?

ps. And a side question.. It seems prefixing RTTI variables with "L" is a convention (and a good one IMO, meta code turns into a puzzle real quick). But what does it actually stand for?

推荐答案

您可以使用From方法使TValue包含aribtrary类型的值.尝试这样的事情:

You can make TValue contain a value of an aribtrary type with the From method. Try something like this:

lValue := TValue.From<TNotifyEvent>(eventHandler);

顺便说一句,我认为L只是一个 L ocal变量.

BTW I think the L just means a Local variable.

这篇关于如何通过新的RTTI设置事件处理程序?[D2010]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆