RTTI - is & as Operator | RTTI | RTTI in Delphi | Delphi Basic | is Operator RTTI | as Operator

Published: 13 June 2023
on channel: DelphiWorld
434
14

What Is RTTI?
RTTI is implemented as data structures generated by the compiler whilst compiling a program. The general idea is to allow information describing various categories of types to be available at run-time for examination and indeed more productive purposes. Normally, types are considered to only be available at compile-time, used by the compiler to identify storage requirements, to ensure appropriate values are used with various variables and so on. RTTI means we have extra information available to query for our own purposes.

Why Do We Have RTTI?
To run the risk of stating the obvious, the Delphi design-time environment allows you to visually design forms that are used in your programs at run-time. It stores the form description in a binary .DFM file, including the type names of all the components placed on the form and also the names and (non-default) values of all form and component properties. At run-time your form file (which was turned into a resource in your EXE during compilation) is read and your EXE magically creates all the objects giving them all the required property values.

In order to get from a string, signifying a class name, to a created object of the required type requires RTTI (or a humungous case statement, which would be a nightmare to maintain). Also, in order to set the values of the named properties in the created objects, bearing in mind they can be of many types, also requires RTTI.

Additionally, the is and as keywords rely on the presence of some form of RTTI to identify if a given object reference is defined in terms of a supplied class type, or one of its descendants. If no information on types was present at run-time then identifying ancestors of any types would be rather tricky.


On this page of the site you can watch the video online RTTI - is & as Operator | RTTI | RTTI in Delphi | Delphi Basic | is Operator RTTI | as Operator with a duration of hours minute second in good quality, which was uploaded by the user DelphiWorld 13 June 2023, share the link with friends and acquaintances, this video has already been watched 434 times on youtube and it was liked by 14 viewers. Enjoy your viewing!