Download MetaTrader 5

Execute a string as a method?

To add comments, please log in or register
rod178
272
rod178  
string methodString= "MyMethod()";
//execute methodString; ??????
How to execute a string as a method?


Keith Watford
Moderator
10570
Keith Watford  
rod178:
How to execute a string as a method?


  if(methodString== "MyMethod()")
     MyMethod();             
rod178
272
rod178  
GumRai:


Not the solution I was looking for

I desire to enter the methods dependent on variable values created. This would include overloading.

Alain Verleyen
Moderator
32530
Alain Verleyen  
rod178:


Not the solution I was looking for

I desire to enter the methods dependent on variable values created. This would include overloading.

You then have to use OOP and pointers.
rod178
272
rod178  
angevoyageur:
You then have to use OOP and pointers.


Yes, that is an option, although I was hoping that a more direct approach was available, as is in some other languages.

eg

eval 'MyMethod()'    # Ruby code to execute a method from  a string
Alain Verleyen
Moderator
32530
Alain Verleyen  
rod178:


Yes, that is an option, although I was hoping that a more direct approach was available, as is in some other languages.

eg

Unfortunately not.
To add comments, please log in or register