Check if a class from a class variable (metaclass) is a TMyClass variable

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

In other words, I need a boolean expression like

var is TMyClass 

but where var is replaced with an expression containing the class reference variable. It sounds simple, but I'm completely at a dead end.

I could create an instance of var: = classRefVar.Create, test it, and then destroy it, but this is a huge overhead.

Oddly enough, the compiler won't let me have

 classRefVar(nil) is TMyClass 

but pleased with seemingly equivalent syntactically but useless

 TMyClass(nil) is TMyClass 

Obviously, the expression

 classRefVar = TMyClass 

is not good because classRefVar may refer to a descendant of TMyClass.

I expect to write it myself when I see the answer ...

+4
source share
1 answer

Easy:

 ClassRefVar.InheritsFrom(TMyClass) 
+7
source

Source: https://habr.com/ru/post/1344271/


All Articles