NemoPeti
NemoPeti

Reputation: 79

Delphi 5 cast type to evaluated type causes Invalid typecast error

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.

Upvotes: 4

Views: 193

Answers (1)

David Heffernan
David Heffernan

Reputation: 613461

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

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

Upvotes: 5

Related Questions