|
|
|
|
|
This article provides an introduction to run-time type information (RTTI). RTTI is information that Delphi stores in the compiled binary file of your application. RTTI is associated with published properties of a component. One of example of how RTTI impacts your everyday use of Delphi is Object Inspector, which displays the names of published properties and is able to edit them. Documentation and compatibility.
All functions and procedures as well as type declarations used by test application are the same under Delphi 3 and Delphi 4. I did not test it under Delphi 5 and any version of C++ Builder. Getting RTTI for enumerated types.Enumerated types are used throughout Delphi. An example - TBitBtnKind type, which declares valid values for the Kind property of TBitBtn component. Type You can do two things with enumerated types using RTTI. You can retrieve a sting - name of the particular value within enum and identify ordinal value from the string representation of the value. 1. Obtain a string equivalent of enum value. 2. Obtain ordinal value from the string representation The first argument of either function is a pointer to the RTTI for an enumerated type. You should use the built-in Typeinfo function to retrieve this information. The second argument is a string or an ordinal correspondingly. Code ExampleVar
Begin
End; The first message box will display "bkHelp" string - a string for fourth value within TBitButtonKind type (enumerated types are zero based). The second message box will display 3 - the ordinal for "bkHelp". Test Project.The use of these functions is demonstrated in the test project, which also demonstrates the use of the BitBtn component from the "Additional" page of the component palette. Figure 1 shows the main form of this project as it might appear while running. Listing 1 contains a source.
Figure 1.
unit Unit1; Go To Page: 1 2
The copyright of the article Run-time type information. Part 1 in Delphi Programming is owned by Lyapin Ilya. Permission to republish Run-time type information. Part 1 in print or online must be granted by the author in writing.
|
|
|
|