Up until this point I have basically used AHK objects as arrays with some functions (which you know ...) , but now I am trying to branch out.
I have a simple object with 5 properties. Every time I change Prop#1 or Prop#2, I want Prop#3 to also change. At the moment I am working on Prop#1's set().
My code is
Code: Select all
class iconClass
{
; XCoordRel := 0
; YCoordRel := 0
; XYCoordRelPacked := 0
; RelToHWND
; IconName := ""
__New(nIconName, XCoord, YCoord, nRelToHWND=false)
{
this.IconName := nIconName
this.RelToHWND := nRelToHWND
this.XCoordRel := XCoord
this.YCoordRel := YCoord
this.XYCoordRelPacked := (XCoord & 0xFFFF) | ((YCoord & 0xFFFF) << 16)
return this
}
XCoordRel
{
set
{
XCoord := value
YCoord := this.YCoordRel
this.XYCoordRelPacked := (XCoord & 0xFFFF) | ((YCoord & 0xFFFF) << 16)
return value
}
}
toString()
{
tmpStr := this.IconName ":" this.XYCoordRelPacked ":" this.XCoordRel "+" this.YCoordRel
return tmpStr
}
}
Code: Select all
iconObj := new iconClass("this is icon", 123, 789, hwWindow)
; outputs
; this is icon::+789
; note lack of XCoordRel & XYCoordRelPacked
Code: Select all
...
iconObj.XCoordRel := 456
; outputs
; this is icon:51708360:+789
; note lack of XCoordRel
(full test code)
Code: Select all
^W::
ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman ; in pre Win10 is "ahk_class WorkerW"
iconObj := new iconClass("this is icon", 123, 789, hwWindow)
tmpStr1 := iconObj.toString() ; this is icon::+789
iconObj.XCoordRel := 456
tmpStr2 := iconObj.toString() ; this is icon:51708360:+789
infoMsgBox(tmpStr1 "`n" tmpStr2)
return
Without using a generic meta-function (for both Prop #1 & Prop#2; I just want a bog-standard set() example), what should I be doing?
Thanks