Access a variable by its name.

Posted by Dominik Loewenstein on 08-May-2017 08:03

Is there a function to get the value of a variable by its name ?

for example:

define variable iX as int init 100.
define variable cName as char init "iX".

display varOfName(cName).

Posted by Roger Blanchard on 08-May-2017 08:08

I do not think you can do that with a variable but you can with a property.

DYNAMIC-PROPERTY (THIS-OBJECT, cName)

All Replies

Posted by Roger Blanchard on 08-May-2017 08:08

I do not think you can do that with a variable but you can with a property.

DYNAMIC-PROPERTY (THIS-OBJECT, cName)

Posted by Laura Stern on 08-May-2017 08:29

That is correct.  

Posted by marian.edu on 08-May-2017 09:38

I think Scott’s EQN were able to do ‘evals’ like that… http://www.oehive.org/node/1006 


A ‘side effect’ of calling a dynamic function in query prepare (http://www.oehive.org/amduus/EQN/eqn/src/evaluate.p)

Marian Edu

Acorn IT 
+40 740 036 212

Posted by Patrick Tingen on 09-May-2017 04:36

EQN could do something like this indeed, but you had to 'feed' it with the variables and their values first. It was all processed dynamically and although it has its purposes, I would only recommend this for special scenario's. We have used it to process generic properties that could be defined by the end-users.

What Dominik asks is not possible with normal variables, but you can get close by defining a temp-table. You create one record in this table and use the fields as variables.

DEFINE VARIABLE cVariable AS CHARACTER NO-UNDO.
DEFINE TEMP-TABLE tt NO-UNDO RCODE-INFORMATION
  FIELD iCounter  AS INTEGER
  FIELD cMyString AS CHARACTER.

CREATE tt.
ASSIGN 
  tt.iCounter  = 3
  tt.cMyString = 'Hello world'.

cVariable = 'iCounter'.

MESSAGE 
  BUFFER tt:BUFFER-FIELD(cVariable):BUFFER-VALUE
  BUFFER tt:BUFFER-FIELD('cMyString'):BUFFER-VALUE
  VIEW-AS ALERT-BOX INFO BUTTONS OK.

Posted by Dominik Loewenstein on 16-May-2017 02:36

Thx for the answers, i have solved it with switch case,i dont really like it but looks like it's the easiest way.

This thread is closed