How does Run-Time Type Information (RTTI) work? - Delphi
How does Run-Time Type Information (RTTI) work?
- The operators that is being used for RTTI are “as” and “is”. The operators are needed to have the information at runtime.
- The “as” operator is a protected typecast that allows the compiler to treat one object at a time.
- This also allows one type to be changed to another type and it shows an error if the type is not compatible with the system.
- The “is” operator allows the user to compare the instances of the object to a class. This is used to test the typecast using “as”.
- The example is shown below:
(MyTime is TSport)
(MyTime is TBasketball)
not (MyTime is TFootball)