Показать сообщение отдельно
Старый 17.04.2015, 23:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,477 / 846 (79) +++++++
Регистрация: 28.10.2006
DeniZone: Assigning enum value to variable from enum name
Источник: http://denizone.blogspot.com/2015/04...able-from.html
==============

Working with utilities there are alot of file exchanges - alot.

Today we got a strange case though. In a file we receive a value that represents the name of a enum value, e.g. E17. The label of the enum value is Consumption, so we wanted to assign the value to a field value in a given table, so this is what we came up with

// must assign Consupmtion and not E17
JournalConnection journalConnection;
str typeOfMeteringPoint = "E17";

SysDictEnum dictEnum = newSysDictEnum(enumNum(ConnectionTypes));
;


journalConnection.type = dictEnum.symbol2Value(typeOfMeteringPoint);









we also came up with this one where we inserted the option of a small if-statement to check if the name of the enum value is found on the enum:

JournalConnection journalConnection;
ConnectionTypes connectionTypes;
str typeOfMeteringPoint = "E17";

SysDictEnum dictEnum = newSysDictEnum(enumNum(ConnectionTypes));
Counter values = dictEnum.values();
int idx;
;

for(idx = 0; idx< values ;idx++)
{
if(typeOfMeteringPoint == dictEnum.index2Symbol(idx))
{
journalConnection.type = str2enum(ConnectionTypes,dictEnum.index2Name(idx));
}

}


Источник: http://denizone.blogspot.com/2015/04...able-from.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.