5

I want to know whether the object that would be created from a class reference is an instance of a particular class or any of its descendants.

In other words, I want a Boolean expression such as

var is TMyClass

but where var is replaced with an expression involving a class reference variable. It sounds easy but has me completely stumped.

I could create an instance var := classRefVar.Create, test it, and then destroy it, but that's a huge overhead.

Oddly, the compiler won't let me have

classRefVar(nil) is TMyClass

but is happy with the seemingly equivalent syntactically, but useless

TMyClass(nil) is TMyClass

Obviously, the expression

classRefVar = TMyClass

is no good because the classRefVar might refer to a descendent of TMyClass.

I'm expecting to kick myself when I see the answer...

1 Answer 1

9

Easy:

ClassRefVar.InheritsFrom(TMyClass)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.