Advertisement
AmourSpirit

Access AutoHotkey nested objects using strings

Apr 14th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Autohotkey using string to access nested objects
  2. ; see: https://autohotkey.com/boards/viewtopic.php?f=5&t=15921&p=80794#p80794
  3.  
  4. #SingleInstance force
  5. #NoEnv
  6. m := "Master.child.SubChild"
  7.  
  8. if(m ~= "[.]+")
  9. {
  10.     MsgBox, Found a dot or so
  11. }
  12.  
  13. StringSplit, outArray, m, .
  14. parent := ""
  15. if(outArray0)
  16. {
  17.     parent := %outArray1%
  18. }
  19. Loop, %outArray0%
  20. {
  21.     if(a_index > 1)
  22.     {
  23.         partname :=  outArray%a_index%
  24.         if(parent.HasKey(partname))
  25.         {
  26.             parent := parent[partname]
  27.         }
  28.         else
  29.         {
  30.             break
  31.         }
  32.     }
  33. }
  34. if(IsObject(parent))
  35. {
  36.     MsgBox, % parent.Name
  37. }
  38. ExitApp
  39.  
  40. class Master
  41. {
  42.     Class child
  43.     {
  44.        
  45.         Class SubChild
  46.         {
  47.             static Name := "SubChild --> Child --> master"
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement