Difference between revisions of "Runtime Type Information (RTTI)"
From Lazarus wiki
Jump to navigationJump to searchm (Text replace - "delphi>" to "syntaxhighlight>") |
m (Fixed syntax highlighting) |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | RTTI can be utilized to obtain | + | {{Editing Runtime Type Information (RTTI)}} |
+ | |||
+ | '''Runtime Type Information RTTI''' can be utilized to obtain meta information in a Pascal application. | ||
+ | |||
+ | |||
__TOC__ | __TOC__ | ||
+ | |||
+ | |||
==Converting a enumerated type to a string== | ==Converting a enumerated type to a string== | ||
+ | One can use RTTI to obtain a string from a enumerated type. | ||
− | + | <syntaxhighlight lang=pascal> | |
+ | uses TypInfo; | ||
− | |||
type | type | ||
TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ; | TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ; | ||
− | |||
− | |||
var | var | ||
Line 16: | Line 21: | ||
s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi)); | s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi)); | ||
// Here s = 'tpDelphi' | // Here s = 'tpDelphi' | ||
+ | WriteLn(s) | ||
+ | end. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | But you can also do it without RTTI: | ||
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
+ | program noRTTI; | ||
+ | type | ||
+ | TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ; | ||
+ | var | ||
+ | s: string; | ||
+ | begin | ||
+ | writestr(s, tpDelphi); | ||
+ | WriteLn(s); | ||
+ | end.</syntaxhighlight> | ||
==See Also== | ==See Also== | ||
− | + | *[[RTTI tab]] | |
*[[RTTI controls]] | *[[RTTI controls]] | ||
− | * http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm | + | * [http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm Run-Time Type Information In Delphi - Can It Do Anything For You?] |
Latest revision as of 14:44, 25 February 2020
│
English (en) │
français (fr) │
русский (ru) │
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.