Converting Integer to Enum

 

I'm communicating with a server (send & receive)

the data sent to my server as integer (0,1,2,3,4 .. and so on)


this OrderSend function takes some data as MqlTradeRequest)

this MqlTradeRequest requires attribute called ENUM_TRADE_REQUEST_ACTIONS    action


I have this ENUM as interger (0,1,2,3,4)

when I pass this integer to the function , it fires error (Invalid Request)


how to convert this number to the original ENUM value ?

 
Ahmed Mohsen: how to convert this number to the original ENUM value ?

You can cast it, but what you should be using is the real enumeration. Why do you have a fake enumeration? Post the code.

 
Ahmed Mohsen:

how to convert this number to the original ENUM value ?

It depends how you convert the ENUM_TRADE_REQUEST_ACTIONS to the integer you send. You might want to use an according "switch" statement on the server, like:

...
ENUM_TRADE_REQUEST_ACTIONS eAction = WRONG_VALUE;
switch(iAction)  // Your integer sent to the server
{
   case 0:
      eAction = ACTION_...;   // The corresponding action
      break;
   case 1:
    .
    .
    .
   default:
      Print("Unknown trade action");   // Not to forget error/plausibility checking
      return false;
}
...
Reason: