Start a Conversation

Unsolved

This post is more than 5 years old

1136

February 11th, 2016 08:00

ASL: Using a variable as a dynamic value for an object property

Dear all,

I am trying to get a variable to be usable as a dynamic property for an object.

This is a sample (and simple) code to list the models of all routers:

START {

.. eol

}

do {

     key="Model"

     foreach router (getInstances("Router")) {

          routerObj = object(router);

          if (!routerObj->isNull()) {

               print("Router : ".routerObj->Name." = ".routerObj->{key});

          }

     }

}

The part in red is obviously wrong (tried to guess, but failed).

Which syntax should I use, so that the value of variable "key" is evaluated and resolved to "Model" and the value routerObj->Model is returned? I need this for a more complex code where the property to be obtained is changing in each loop...

An also valid alternative would a be if a function would exist similar to getObjectProperty(object,parameter) which returns the value, but I don't know of any.

Would you please help me to make it work?

Thank you in advance and regards,

Hector

No Responses!
No Events found!

Top