Question

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 needs a TValue passed but I've yet to find a way to represent a TMethod via a TValue. Any comments?

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?

Was it helpful?

Solution

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

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

BTW I think the L just means a Local variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top