Does VarSetCapacity not work for class variable?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
magusneo
Posts: 45
Joined: 30 Sep 2013, 06:34

Does VarSetCapacity not work for class variable?

09 Nov 2013, 22:05

"VarSetCapacity" Can't get correct outputs,"SetCapacity" works.

Code: Select all

class myclass{
	static field:="1234567890"
	__New(p){
		VarSetCapacity(this.field,256)
		;~ this.SetCapacity("field", 256)
		
		StrPut("abc", this.GetAddress("field"))
		MsgBox, % StrGet(this.GetAddress("field"),10)
		MsgBox,% this.field
	}
}
lexikos
Posts: 9683
Joined: 30 Sep 2013, 04:07
Contact:

Re: Does VarSetCapacity not work for class variable?

10 Nov 2013, 01:33

this.field is not a variable reference (or as the documentation for VarSetCapacity puts it, the name of a variable). It is a sub-expression which retrieves a value from the object. The value it retrieves is not a variable reference either, so no, VarSetCapacity won't work.

A "class variable" is also not a variable in the same sense as local and global variables. The declaration does not affect the meaning of this.field; it's just one way to create a key-value pair. I probably should have called them "instance assignments" and "class assignments" rather than "instance variable declarations" and "class variable declarations".
magusneo
Posts: 45
Joined: 30 Sep 2013, 06:34

Re: Does VarSetCapacity not work for class variable?

10 Nov 2013, 02:23

Learned more about class in AHK.Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 92 guests