Dynamic attribute setter and getter

  • Hello!

    It's maybe a feature request.

    I'll like to know if there is a simple way to access an element attribute "dynamically", i.e. programmatically, using something like:

    Code
    set( myAttribute, ... );
    get( hotspot[get(hotspotName)].%myAttribute )

    Today, I'm not able to access an attribute I do not already know.

    My workarround is quite tedious: let's say 'myAttribute' contains the name of the attribute I want to read from...

    Code
    if( get(myAttribute) === 'name', copy( myValue, hotspot[get(hotspotName)].name ));
    if( get(myAttribute) === 'attr1', copy( myValue, hotspot[get(hotspotName)].attr1 ));
    if( get(myAttribute) === 'attr2', copy( myValue, hotspot[get(hotspotName)].attr2 ));
    ...


    Imagine when I got a panel with about 15-20 attributes to read... :)

    Best regards

    « Quidquid latine dictum sit, altum sonatur »
    Pentax stuff.

  • Hi,

    here two possibilities:

    for version 1.19 and higher:

    Code
    set(myAttribute, ...);
    copy(myValue, calc('hotspot[get(hotspotName)].' + myAttribute));

    for version 1.18 and lower:

    Code
    set(myAttribute, ... );
    txtadd(tmp, 'hotspot[get(hotspotName)].', get(myAttribute) );
    copy(myValue, get(tmp));

    Both examples are basically doing the same - first building a string with with the 'full path/name' to the attribute and then getting the value from it.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!