- @Helgef: Thanks for the switch() example.
- Btw the GeekDude tutorials are very good, and short, if you ever get a chance to read them:
[note: the tips and tricks tutorial has some useful information re. objects]
Classes in AHK, a Dissection (Advanced) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6177
GeekDude's tips and tricks - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=7190
How to create custom enumerator objects - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=7199
- Some example code for checking whether something is a key or a property:
E.g. __Class is a key, base is a property, the items in an Exception object are keys not properties, despite what the documentation says here:
Throw
https://autohotkey.com/docs/commands/Throw.htm
Exception(Message [, What, Extra])
Creates an object with the following properties
Although in the documentation's defence, a key effectively works like a property in many respects.
Code: Select all
q:: ;test Exception object keys/properties
obj := Exception("MyMessage", "MyWhat", "MyExtra")
vOutput := ""
for vKey, vValue in obj
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
;MsgBox, % obj.Message
;MsgBox, % obj.What
;MsgBox, % obj.Extra
;MsgBox, % obj.File
;MsgBox, % obj.Line
;MsgBox, % obj.HasKey("Message") ;1
;MsgBox, % obj.HasKey("What") ;1
;MsgBox, % obj.HasKey("Extra") ;1
;MsgBox, % obj.HasKey("File") ;1
;MsgBox, % obj.HasKey("Line") ;1
vOutput := ""
for vKey, vValue in obj.base
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
return
w:: ;list keys/properties
oArray := new MyKeyAndPropertyClass
;info from properties not listed in for loop
vOutput := ""
for vKey, vValue in oArray
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(MyProperty is not in the list)
MsgBox, % oArray.HasKey("MyKey") ;1
MsgBox, % oArray.HasKey("MyKey2") ;1
MsgBox, % oArray.HasKey("MyProperty") ;0
MsgBox, % oArray.MyProperty ;property
vOutput := ""
for vKey, vValue in oArray.base
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput ;(MyProperty is in the list)
return
class MyKeyAndPropertyClass
{
MyKey := "key"
__New()
{
this.MyKey2 := "key2"
}
MyProperty
{
get
{
return "property"
}
set
{
}
}
}