This value of type "class" has no property named "blah blah"

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
wpb
Posts: 139
Joined: 14 Dec 2015, 01:53

This value of type "class" has no property named "blah blah"

Post by wpb » 28 Mar 2023, 14:49

When I run this code:

Code: Select all

#Requires AutoHotkey v2.0

instance := cInherited("NO OWNER", "My object", "notepad.exe")

class cBase
{
	__New(Owner, objectName)
	{
		this.Owner := Owner
		this.objectName := objectName
	}
}

class cInherited extends cBase
{
	static msDefaultPeriod := 1000

	__New(Owner, objectName, processName)
	{
		super.__New(Owner, objectName)
		; Set up a hover timer, to check for hovering.
		this.msPeriod := this.msDefaultPeriod
	}
}
this.msDefaultPeriod can't be found. AHK reports: This value of type "cInherited" has no property named "msDefaultPeriod".

Why is that?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: This value of type "class" has no property named "blah blah"

Post by swagfag » 28 Mar 2023, 20:30

because uve declared "msDefaultPeriod" as a static property. the property is an ownproperty of the object "cInherited", so to access it u write "cInherited.msDefaultPeriod"

wpb
Posts: 139
Joined: 14 Dec 2015, 01:53

Re: This value of type "class" has no property named "blah blah"

Post by wpb » 29 Mar 2023, 02:44

Thanks - I suspected that might be the case.

But is there no other way? If I were to change the name of the class, I'd have to change all references to its internal static variables.

User avatar
Mono919
Posts: 71
Joined: 05 May 2022, 02:36

Re: This value of type "class" has no property named "blah blah"

Post by Mono919 » 29 Mar 2023, 02:48

wpb wrote:
29 Mar 2023, 02:44
Thanks - I suspected that might be the case.

But is there no other way? If I were to change the name of the class, I'd have to change all references to its internal static variables.
delete "static"

wpb
Posts: 139
Joined: 14 Dec 2015, 01:53

Re: This value of type "class" has no property named "blah blah"

Post by wpb » 29 Mar 2023, 03:27

Haha, thanks, I guess that's the obvious solution.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: This value of type "class" has no property named "blah blah"

Post by swagfag » 29 Mar 2023, 06:24

idk about it being the obvious solution, but is one of possible solutions, the others being:
  • trying to deref the class's name back to a class object(with the caveat that whether doing that is possible would depend on the surrounding context in which the code is executed)

    Code: Select all

    this.msPeriod := %this.__Class%.msDefaultPeriod
  • store some circular references

    Code: Select all

    class cBase
    {
    	static __New() {
    		this.Prototype.DefineProp('MyCustomClassProperty', { Get: (*) => this })
    	}
    ...
    class cInherited extends cBase
    {
    	static msDefaultPeriod := 1000
    
    	__New(Owner, objectName, processName)
    	{
    		super.__New(Owner, objectName)
    		; Set up a hover timer, to check for hovering.
    		this.msPeriod := this.MyCustomClassProperty.msDefaultPeriod
wpb wrote:
29 Mar 2023, 02:44
If I were to change the name of the class, I'd have to change all references to its internal static variables.
if u were to change the name of the class, ud have to change all references period. so, moot point

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: This value of type "class" has no property named "blah blah"

Post by kczx3 » 29 Mar 2023, 08:12

I find PHP's Late Static Binding to be quite useful. Perhaps some day AutoHotkey will have such a feature.

wpb
Posts: 139
Joined: 14 Dec 2015, 01:53

Re: This value of type "class" has no property named "blah blah"

Post by wpb » 30 Mar 2023, 15:20

Thanks for the extra thoughts on this. %this.__Class% probably would work in my situation - cheers.

Post Reply

Return to “Ask for Help (v2)”