Attribute 'to_string'

The pragma has an effect on how the result of the conversion of an enumeration component with the operator TO_STRING/TO_WSTRING is output: If the enumeration declaration is provided with the pragma, the name of the enumeration component appears as a string instead of the numerical value.

Syntax: {attribute 'to_string'}

Insertion location: Line above the declaration of the enumeration.

Attribute 'to_string' 1:

Available from TC3.1 Build 4024

Sample:

Enumeration E_Sample

{attribute 'qualified_only'}
{attribute 'strict'}
{attribute 'to_string'}
TYPE E_Sample :
(
    eInit := 0,
    eStart,
    eStop
);
END_TYPE

Program MAIN

PROGRAM MAIN
VAR
    eSample         : E_Sample;
    nCurrentValue   : INT;
    sCurrentValue   : STRING;
    wsCurrentValue  : WSTRING;
 
    sComponent      : STRING;
    wsComponent     : WSTRING;
END_VAR
nCurrentValue  := eSample; 
sCurrentValue  := TO_STRING(eSample);
wsCurrentValue := TO_WSTRING(eSample);

sComponent     := TO_STRING(E_Sample.eStart);
wsComponent    := TO_WSTRING(E_Sample.eStop);

 

Result of the assignments/conversion functions:

 

Result if the enumeration were not to be declared with the attribute 'to_string':

See also: