Runtime Type Information (RTTI)
Runtime Type Information RTTI can be utilized to obtain meta information in a Pascal application.
Converting a enumerated type to a string
One can use RTTI to obtain a string from a enumerated type.
uses TypInfo;
type
TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
var
s: string;
begin
s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi));
// Here s = 'tpDelphi'
WriteLn(s)
end.But you can also do it without RTTI:
program noRTTI;
type
TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
var
s: string;
begin
writestr(s, tpDelphi);
WriteLn(s);
end.See Also
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.
Edited on wiki.freepascal.org by 8 people, 2011–2020
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Sekelsenmat | New page: RTTI can be utilized to obtain a number of meta information in a Pascal application. ==Converting a enumerated type to a string== One can use RTTI to obtain a string from a enumerated ty... | |
| Sekelsenmat | ||
| Sekelsenmat | See Also | |
| Sekelsenmat | ||
| Vincent | Text replace - "delphi>" to "syntaxhighlight>" (minor) | |
| Amber | ||
| Amber | ||
| FPC user | Converting a enumerated type to a string: move uses clause to the top. | |
| Arent | ||
| Arent | ||
| Arent | ||
| Thaddy | Converting a enumerated type to a string | |
| Mathias | Converting a enumerated type to a string (minor) | |
| Trev | Fixed syntax highlighting (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
