Delphi 5 cast type to evaluated type causes Invalid typecast error

Viewed 164

debug time

I need to convert a Variant to TNotifyEvent, but can't.

As the image shows I use GetPropValue to get the OnClick property of a TMenuItem. I must compare this to another TNotifyEvent, so I must convert it also to TNotifyEvent.

In runtime this is always type of TNotifyEvent, but the code not compile, when I try to cast it to TNotifyEvent.

How can I make it work? Unfortunately I have only Delphi version 5, so the RTTI capabilities are limited.

1 Answers

You are calling the wrong method. Instead of GetPropValue you need GetMethodProp. Like so:

TNotifyEvent(GetMethodProp(MenuItem, 'OnClick'));
Related