Difference between revisions of "Runtime Type Information (RTTI)"

From Lazarus wiki
m (Text replace - "delphi>" to "syntaxhighlight>")
Line 5: Line 5:
 
One can use RTTI to obtain a string from a enumerated type.
 
One can use RTTI to obtain a string from a enumerated type.
  
<delphi>
+
<syntaxhighlight>
 
type
 
type
 
   TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
 
   TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;
Line 16: Line 16:
 
   s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi));
 
   s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi));
 
   // Here s = 'tpDelphi'
 
   // Here s = 'tpDelphi'
</delphi>
+
</syntaxhighlight>
  
 
==See Also==
 
==See Also==

Revision as of 15:55, 24 March 2012

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 type.

type
  TProgrammerType = (tpDelphi, tpVisualC, tpVB, tpJava) ;

uses TypInfo;

var 
  s: string;
begin
  s := GetEnumName(TypeInfo(TProgrammerType), integer(tpDelphi));
  // Here s = 'tpDelphi'

See Also