AmourSpirit icon

Access AutoHotkey nested objects using strings

AmourSpirit | PRO | 04/15/16 02:52:23 AM UTC | 0 ⭐ | 549 👁️ | Never ⏰ | []
Autohotkey |

690 B

|

None

|

0 👍

/

0 👎

; Autohotkey using string to access nested objects
; see: https://autohotkey.com/boards/viewtopic.php?f=5&t=15921&p=80794#p80794
 
#SingleInstance force
#NoEnv
m := "Master.child.SubChild"
 
if(m ~= "[.]+")
{
    MsgBox, Found a dot or so
}
 
StringSplit, outArray, m, .
parent := ""
if(outArray0)
{
    parent := %outArray1%
}
Loop, %outArray0%
{
    if(a_index > 1)
    {
        partname :=  outArray%a_index%
        if(parent.HasKey(partname))
        {
            parent := parent[partname]
        }
        else
        {
            break
        }
    }
}
if(IsObject(parent))
{
    MsgBox, % parent.Name
}
ExitApp
 
class Master
{
    Class child
    {
        
        Class SubChild
        {
            static Name := "SubChild --> Child --> master"
        }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎