How to dynamically access a objects properties?

21 Views Asked by At
global _ditto                   := {}
_ditto.search                   := {}
_ditto.search.description   := 16
_ditto.search.fullText      := 38
_ditto.search.quickPaste    := 60

_ditto.search.containsText  := 91
_ditto.search.regEx         := 113
_ditto.search.wildcard      := 135

If I have the above _ditto object, I want to access the objects properties by just referencing the properties name from a string. The following is a barebones example of my final function:

foo("containsText")
foo(thisProperty){
    ;OutputDebug,% _ditto.search.%thisProperty%         ; Error:        ==> Ambiguous or invalid use of "."
    ;OutputDebug,% _ditto.search . %thisProperty%       ; Warning:  ==> Warning: This variable has not been assigned a value. Specifically: containsText
    OutputDebug,% _ditto.search "." thisProperty            ; merely prints ".containsText"
}

I am expecting OutputDebug,% _ditto.search . %thisProperty% to print the value 91 which is what the property _ditto.search.containsText has.

But each attempt just fails. Is this actually possible?

0

There are 0 best solutions below