How to install event handlers through the new RTTI? [D2010]

Playing with the new RTTI module, I could not find a way to install an event handler with new utilities. Try something like this:

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

SetValue needs a TValue broadcast, but I have not yet found a way to present TMethod via TValue. Any comments?

ps. And a side question. The prefix of RTTI variables with "L" seems to be a convention (and a good IMO, the meta code turns into a puzzle very quickly). But what is it really worth?

+4
source share
1 answer

You can force TValue to contain an aribtrary value using the From method. Try something like this:

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

BTW I think L just means the variable o L.

+4
source

All Articles