Sign in Join
Wiki copytemporary

Runtime Type Information (RTTI): what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Runtime Type Information (RTTI)

OldNewLine
1+**Runtime Type Information RTTI** can be utilized to obtain meta information in a Pascal application.
2+
3+## Converting a enumerated type to a string
4+
5+One can use RTTI to obtain a string from a enumerated type.
6+
7+``` pascal
8+uses TypInfo;
9+
10+type
11+ TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
12+
13+var
14+ s: string;
15+begin
16+ s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi));
17+ // Here s = 'tpDelphi'
18+ WriteLn(s)
19+end.
20+```
21+
22+But you can also do it without RTTI:
23+
24+``` pascal
25+program noRTTI;
26+type
27+ TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
28+var
29+ s: string;
30+begin
31+ writestr(s, tpDelphi);
32+ WriteLn(s);
33+end.
34+```
35+
36+## See Also
37+
38+- [[RTTI tab]]
39+- [[RTTI controls]]
40+- [Run-Time Type Information In Delphi - Can It Do Anything For You?](http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm)
41+
42+---
43+*From the Free Pascal wiki, page "Runtime Type Information (RTTI)", as it stood on 2020-02-25 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history